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

getspawnpoint_nearteam( var_0 )
{
    var_0 = checkdynamicspawns( var_0 );
    var_1["primary"] = [];
    var_1["secondary"] = [];
    var_1["bad"] = [];

    foreach ( var_3 in var_0 )
    {
        initscoredata( var_3 );
        var_4 = criticalfactors_nearteam( var_3 );
        var_1[var_4][var_1[var_4].size] = var_3;
    }

    if ( var_1["primary"].size )
        return scorespawns_nearteam( var_1["primary"] );

    if ( var_1["secondary"].size )
        return scorespawns_nearteam( var_1["secondary"] );

    logbadspawn( "Buddy Spawn" );
    return selectbestspawnpoint( var_0[0], var_0 );
}

scorespawns_nearteam( var_0 )
{
    var_1 = var_0[0];

    foreach ( var_3 in var_0 )
    {
        scorefactors_nearteam( var_3 );

        if ( var_3.totalscore > var_1.totalscore )
            var_1 = var_3;
    }

    var_1 = selectbestspawnpoint( var_1, var_0 );
    return var_1;
}

checkdynamicspawns( var_0 )
{
    if ( isdefined( level.dynamicspawns ) )
        var_0 = [[ level.dynamicspawns ]]( var_0 );

    return var_0;
}

selectbestspawnpoint( var_0, var_1 )
{
    var_2 = var_0;
    var_3 = 0;

    foreach ( var_5 in var_1 )
    {
        if ( var_5.totalscore > 0 )
            var_3++;
    }

    if ( var_3 == 0 || level.forcebuddyspawn )
    {
        if ( level.teambased && level.supportbuddyspawn )
        {
            var_7 = findbuddyspawn();

            if ( var_7.buddyspawn )
                var_2 = var_7;
        }

        if ( var_2.totalscore == 0 )
        {
            logbadspawn( "UNABLE TO BUDDY SPAWN. Extremely bad." );
            var_2 = var_1[randomint( var_1.size )];
        }
    }

    return var_2;
}

findsecondhighestspawnscore( var_0, var_1 )
{
    if ( var_1.size < 2 )
        return var_0;

    var_2 = var_1[0];

    if ( var_2 == var_0 )
        var_2 = var_1[1];

    foreach ( var_4 in var_1 )
    {
        if ( var_4 == var_0 )
            continue;

        if ( var_4.totalscore > var_2.totalscore )
            var_2 = var_4;
    }

    return var_2;
}

findbuddyspawn()
{
    var_0 = spawnstruct();
    initscoredata( var_0 );
    var_1 = getteammatesoutofcombat( self.team );
    var_2 = spawnstruct();
    var_2.maxtracecount = 18;
    var_2.currenttracecount = 0;

    foreach ( var_4 in var_1 )
    {
        var_5 = findspawnlocationnearplayer( var_4 );

        if ( !isdefined( var_5 ) )
            continue;

        if ( issafetospawnon( var_4, var_5, var_2 ) )
        {
            var_0.totalscore = 999;
            var_0.buddyspawn = 1;
            var_0.origin = var_5;
            var_0.angles = getbuddyspawnangles( var_4, var_0.origin );
            break;
        }

        if ( var_2.currenttracecount == var_2.maxtracecount )
            break;
    }

    return var_0;
}

getbuddyspawnangles( var_0, var_1 )
{
    var_2 = ( 0, var_0.angles[1], 0 );
    var_3 = findentrances( var_1 );

    if ( isdefined( var_3 ) && var_3.size > 0 )
        var_2 = vectortoangles( var_3[0].origin - var_1 );

    return var_2;
}

getteammatesoutofcombat( var_0 )
{
    var_1 = [];

    foreach ( var_3 in level.players )
    {
        if ( var_3.team != var_0 )
            continue;

        if ( var_3.sessionstate != "playing" )
            continue;

        if ( !maps\mp\_utility::isreallyalive( var_3 ) )
            continue;

        if ( var_3 == self )
            continue;

        if ( isplayerincombat( var_3 ) )
            continue;

        var_1[var_1.size] = var_3;
    }

    return common_scripts\utility::array_randomize( var_1 );
}

isplayerincombat( var_0, var_1 )
{
    if ( var_0 issighted() )
    {
        debugcombatcheck( var_0, "IsSighted" );
        return 1;
    }

    if ( !var_0 isonground() )
    {
        debugcombatcheck( var_0, "IsOnGround" );
        return 1;
    }

    if ( var_0 isonladder() )
    {
        debugcombatcheck( var_0, "IsOnLadder" );
        return 1;
    }

    if ( var_0 common_scripts\utility::isflashed() )
    {
        debugcombatcheck( var_0, "isFlashed" );
        return 1;
    }

    if ( isdefined( var_1 ) && var_1 )
    {
        if ( var_0.health < var_0.maxhealth && ( !isdefined( var_0.lastdamagedtime ) || gettime() < var_0.lastdamagedtime + 3000 ) )
        {
            debugcombatcheck( var_0, "RecentDamage" );
            return 1;
        }
    }
    else if ( var_0.health < var_0.maxhealth )
    {
        debugcombatcheck( var_0, "MaxHealth" );
        return 1;
    }

    if ( !maps\mp\gametypes\_spawnfactor::avoidgrenades( var_0 ) )
    {
        debugcombatcheck( var_0, "Grenades" );
        return 1;
    }

    if ( !maps\mp\gametypes\_spawnfactor::avoidmines( var_0 ) )
    {
        debugcombatcheck( var_0, "Mines" );
        return 1;
    }

    return 0;
}

debugcombatcheck( var_0, var_1 )
{
    var_2 = "none";

    if ( isdefined( var_0.battlebuddy ) )
        var_2 = var_0.battlebuddy.name;

    bbprint( "battlebuddy_spawn", "player %s buddy %s reason %s", var_0.name, var_2, var_1 );
}

findspawnlocationnearplayer( var_0 )
{
    var_1 = maps\mp\gametypes\_spawnlogic::getplayertraceheight( var_0, 1 );
    var_2 = findbuddypathnode( var_0, var_1, 0.5 );

    if ( isdefined( var_2 ) )
        return var_2.origin;

    return undefined;
}

findbuddypathnode( var_0, var_1, var_2 )
{
    var_3 = getnodesinradiussorted( var_0.origin, 192, 64, var_1, "Path" );
    var_4 = undefined;

    if ( isdefined( var_3 ) && var_3.size > 0 )
    {
        var_5 = anglestoforward( var_0.angles );

        foreach ( var_7 in var_3 )
        {
            var_8 = vectornormalize( var_7.origin - var_0.origin );
            var_9 = vectordot( var_5, var_8 );

            if ( maps\mp\_utility::getmapname() == "mp_fahrenheit" )
            {
                if ( var_7.origin == ( 1778.9, 171.6, 716 ) || var_7.origin == ( 1772.1, 271.4, 716 ) || var_7.origin == ( 1657.2, 259.6, 716 ) || var_7.origin == ( 1633.7, 333.9, 716 ) || var_7.origin == ( 1634.4, 415.7, 716 ) || var_7.origin == ( 1537.3, 419.3, 716 ) || var_7.origin == ( 1410.9, 420.8, 716 ) || var_7.origin == ( 1315.6, 416.6, 716 ) || var_7.origin == ( 1079.4, 414.6, 716 ) || var_7.origin == ( 982.9, 421.8, 716 ) || var_7.origin == ( 896.9, 423.8, 716 ) )
                    continue;
            }

            if ( var_9 <= var_2 && !positionwouldtelefrag( var_7.origin ) )
            {
                if ( sighttracepassed( var_0.origin + ( 0, 0, var_1 ), var_7.origin + ( 0, 0, var_1 ), 0, var_0 ) )
                {
                    var_4 = var_7;

                    if ( var_9 <= 0.0 )
                        break;
                }
            }
        }
    }

    return var_4;
}

finddronepathnode( var_0, var_1, var_2, var_3 )
{
    var_4 = getnodesinradiussorted( var_0.origin, var_3, 32, var_1, "Path" );
    var_5 = undefined;

    if ( isdefined( var_4 ) && var_4.size > 0 )
    {
        var_6 = anglestoforward( var_0.angles );

        foreach ( var_8 in var_4 )
        {
            var_9 = var_8.origin + ( 0, 0, var_1 );

            if ( capsuletracepassed( var_9, var_2, var_2 * 2 + 0.01, undefined, 1, 1 ) )
            {
                if ( bullettracepassed( var_0 geteye(), var_9, 0, var_0 ) )
                {
                    var_5 = var_9;
                    break;
                }
            }
        }
    }

    return var_5;
}

issafetospawnon( var_0, var_1, var_2 )
{
    if ( var_0 issighted() )
    {
        debugcombatcheck( self, "IsSighted-2" );
        return 0;
    }

    foreach ( var_4 in level.players )
    {
        if ( var_2.currenttracecount == var_2.maxtracecount )
        {
            debugcombatcheck( self, "TooManyTraces" );
            return 0;
        }

        if ( var_4.team == self.team )
            continue;

        if ( var_4.sessionstate != "playing" )
            continue;

        if ( !maps\mp\_utility::isreallyalive( var_4 ) )
            continue;

        if ( var_4 == self )
            continue;

        var_2.currenttracecount++;
        var_5 = maps\mp\gametypes\_spawnlogic::getplayertraceheight( var_4 );
        var_6 = var_4 geteye();
        var_6 = ( var_6[0], var_6[1], var_4.origin[2] + var_5 );
        var_7 = spawnsighttrace( var_2, var_1 + ( 0, 0, var_5 ), var_6 );

        if ( var_7 > 0 )
        {
            debugcombatcheck( self, "lineOfSight" );
            return 0;
        }
    }

    return 1;
}

initscoredata( var_0 )
{
    var_0.totalscore = 0;
    var_0.numberofpossiblespawnchoices = 0;
    var_0.buddyspawn = 0;
}

criticalfactors_nearteam( var_0 )
{
    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidfullvisibleenemies, var_0 ) )
        return "bad";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidgrenades, var_0 ) )
        return "bad";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidmines, var_0 ) )
        return "bad";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidairstrikelocations, var_0 ) )
        return "bad";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidcarepackages, var_0 ) )
        return "bad";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidtelefrag, var_0 ) )
        return "bad";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidenemyspawn, var_0 ) )
        return "bad";

    if ( isdefined( var_0.forcedteam ) && var_0.forcedteam != self.team )
        return "bad";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidcornervisibleenemies, var_0 ) )
        return "secondary";

    if ( !maps\mp\gametypes\_spawnfactor::critical_factor( maps\mp\gametypes\_spawnfactor::avoidcloseenemies, var_0 ) )
        return "secondary";

    return "primary";
}

scorefactors_nearteam( var_0 )
{
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 1.25, maps\mp\gametypes\_spawnfactor::preferalliesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyenemies, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidenemiesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidlastdeathlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidlastattackerlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidsamespawn, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyanyone, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
}

criticalfactors_dz( var_0 )
{
    return criticalfactors_nearteam( var_0 );
}

getspawnpoint_dz( var_0, var_1 )
{
    var_0 = checkdynamicspawns( var_0 );
    var_2["primary"] = [];
    var_2["secondary"] = [];
    var_2["bad"] = [];

    foreach ( var_4 in var_0 )
    {
        initscoredata( var_4 );
        var_5 = criticalfactors_dz( var_4 );
        var_2[var_5][var_2[var_5].size] = var_4;
    }

    if ( var_2["primary"].size )
        return scorespawns_dz( var_2["primary"], var_1 );

    if ( var_2["secondary"].size )
        return scorespawns_dz( var_2["secondary"], var_1 );

    return selectbestspawnpoint( var_0[0], var_0 );
}

getspawnpoint_domination( var_0, var_1 )
{
    var_0 = checkdynamicspawns( var_0 );
    var_2["primary"] = [];
    var_2["secondary"] = [];
    var_2["bad"] = [];

    foreach ( var_4 in var_0 )
    {
        initscoredata( var_4 );
        var_5 = criticalfactors_domination( var_4 );
        var_2[var_5][var_2[var_5].size] = var_4;
    }

    if ( var_2["primary"].size )
        return scorespawns_domination( var_2["primary"], var_1 );

    if ( var_2["secondary"].size )
        return scorespawns_domination( var_2["secondary"], var_1 );

    logbadspawn( "Buddy Spawn" );
    return selectbestspawnpoint( var_0[0], var_0 );
}

scorespawns_dz( var_0, var_1 )
{
    var_2 = var_0[0];

    foreach ( var_4 in var_0 )
    {
        scorefactors_dz( var_4, var_1 );

        if ( var_4.totalscore > var_2.totalscore )
            var_2 = var_4;
    }

    var_2 = selectbestspawnpoint( var_2, var_0 );
    return var_2;
}

scorespawns_domination( var_0, var_1 )
{
    var_2 = var_0[0];

    foreach ( var_4 in var_0 )
    {
        scorefactors_domination( var_4, var_1 );

        if ( var_4.totalscore > var_2.totalscore )
            var_2 = var_4;
    }

    var_2 = selectbestspawnpoint( var_2, var_0 );
    return var_2;
}

criticalfactors_domination( var_0 )
{
    return criticalfactors_nearteam( var_0 );
}

scorefactors_dz( var_0, var_1 )
{
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 2.5, maps\mp\gametypes\_spawnfactor::preferclosepoints, var_0, var_1 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::preferalliesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyenemies, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidenemiesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidlastdeathlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidlastattackerlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidsamespawn, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyanyone, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
}

scorefactors_domination( var_0, var_1 )
{
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 2.5, maps\mp\gametypes\_spawnfactor::preferdompoints, var_0, var_1 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::preferalliesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyenemies, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidenemiesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidlastdeathlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidlastattackerlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidsamespawn, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyanyone, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
}

getstartspawnpoint_freeforall( var_0 )
{
    if ( !isdefined( var_0 ) )
        return undefined;

    var_1 = undefined;
    var_2 = maps\mp\gametypes\_spawnlogic::getactiveplayerlist();
    var_0 = checkdynamicspawns( var_0 );

    if ( !isdefined( var_2 ) || var_2.size == 0 )
        return maps\mp\gametypes\_spawnlogic::getspawnpoint_random( var_0 );

    var_3 = 0;

    foreach ( var_5 in var_0 )
    {
        if ( canspawn( var_5.origin ) && !positionwouldtelefrag( var_5.origin ) )
        {
            var_6 = undefined;

            foreach ( var_8 in var_2 )
            {
                var_9 = distancesquared( var_5.origin, var_8.origin );

                if ( !isdefined( var_6 ) || var_9 < var_6 )
                    var_6 = var_9;
            }

            if ( !isdefined( var_1 ) || var_6 > var_3 )
            {
                var_1 = var_5;
                var_3 = var_6;
            }
        }
    }

    if ( !isdefined( var_1 ) )
        return maps\mp\gametypes\_spawnlogic::getspawnpoint_random( var_0 );

    return var_1;
}

getspawnpoint_freeforall( var_0 )
{
    var_0 = checkdynamicspawns( var_0 );
    var_1["primary"] = [];
    var_1["secondary"] = [];
    var_1["bad"] = [];

    foreach ( var_3 in var_0 )
    {
        initscoredata( var_3 );
        var_4 = criticalfactors_freeforall( var_3 );
        var_1[var_4][var_1[var_4].size] = var_3;
    }

    if ( var_1["primary"].size )
        return scorespawns_freeforall( var_1["primary"] );

    if ( var_1["secondary"].size )
        return scorespawns_freeforall( var_1["secondary"] );

    if ( getdvarint( "scr_altFFASpawns" ) == 1 && var_1["bad"].size )
    {
        logbadspawn( "Bad FFA Spawn" );
        return scorespawns_freeforall( var_1["bad"] );
    }

    logbadspawn( "FFA Random Spawn" );
    return selectbestspawnpoint( var_0[0], var_0 );
}

scorespawns_freeforall( var_0 )
{
    var_1 = var_0[0];

    foreach ( var_3 in var_0 )
    {
        scorefactors_freeforall( var_3 );

        if ( var_3.totalscore > var_1.totalscore )
            var_1 = var_3;
    }

    var_1 = selectbestspawnpoint( var_1, var_0 );
    return var_1;
}

criticalfactors_freeforall( var_0 )
{
    return criticalfactors_nearteam( var_0 );
}

scorefactors_freeforall( var_0 )
{
    var_1 = 3.0;

    if ( getdvarint( "scr_altFFASpawns" ) == 1 )
    {
        var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 3.0, maps\mp\gametypes\_spawnfactor::avoidclosestenemy, var_0 );
        var_0.totalscore = var_0.totalscore + var_2;
        var_1 = 2.0;
    }

    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( var_1, maps\mp\gametypes\_spawnfactor::avoidenemiesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 2.0, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyenemies, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidlastdeathlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidlastattackerlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidsamespawn, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
}

getspawnpoint_searchandrescue( var_0 )
{
    var_0 = checkdynamicspawns( var_0 );
    var_1["primary"] = [];
    var_1["secondary"] = [];
    var_1["bad"] = [];

    foreach ( var_3 in var_0 )
    {
        initscoredata( var_3 );
        var_4 = criticalfactors_searchandrescue( var_3 );
        var_1[var_4][var_1[var_4].size] = var_3;
    }

    if ( var_1["primary"].size )
        return scorespawns_searchandrescue( var_1["primary"] );

    if ( var_1["secondary"].size )
        return scorespawns_searchandrescue( var_1["secondary"] );

    logbadspawn( "Buddy Spawn" );
    return selectbestspawnpoint( var_0[0], var_0 );
}

scorespawns_searchandrescue( var_0 )
{
    var_1 = var_0[0];

    foreach ( var_3 in var_0 )
    {
        scorefactors_searchandrescue( var_3 );

        if ( var_3.totalscore > var_1.totalscore )
            var_1 = var_3;
    }

    var_1 = selectbestspawnpoint( var_1, var_0 );
    return var_1;
}

criticalfactors_searchandrescue( var_0 )
{
    return criticalfactors_nearteam( var_0 );
}

scorefactors_searchandrescue( var_0 )
{
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 3.0, maps\mp\gametypes\_spawnfactor::avoidenemiesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::preferalliesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidlastdeathlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidlastattackerlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
}

getspawnpoint_awayfromenemies( var_0, var_1, var_2 )
{
    if ( !isdefined( var_2 ) )
        var_2 = 0;

    var_0 = checkdynamicspawns( var_0 );
    var_3["primary"] = [];
    var_3["secondary"] = [];
    var_3["bad"] = [];

    foreach ( var_5 in var_0 )
    {
        initscoredata( var_5 );
        var_6 = criticalfactors_awayfromenemies( var_5 );
        var_3[var_6][var_3[var_6].size] = var_5;
    }

    if ( var_3["primary"].size )
        return scorespawns_awayfromenemies( var_3["primary"], var_1 );

    if ( var_3["secondary"].size )
        return scorespawns_awayfromenemies( var_3["secondary"], var_1 );

    if ( var_2 )
        return undefined;
    else
    {
        logbadspawn( "Buddy Spawn" );
        return selectbestspawnpoint( var_0[0], var_0 );
    }
}

scorespawns_awayfromenemies( var_0, var_1 )
{
    var_2 = var_0[0];

    foreach ( var_4 in var_0 )
    {
        scorefactors_awayfromenemies( var_4, var_1 );

        if ( var_4.totalscore > var_2.totalscore )
            var_2 = var_4;
    }

    var_2 = selectbestspawnpoint( var_2, var_0 );
    return var_2;
}

criticalfactors_awayfromenemies( var_0 )
{
    return criticalfactors_nearteam( var_0 );
}

scorefactors_awayfromenemies( var_0, var_1 )
{
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 2.0, maps\mp\gametypes\_spawnfactor::avoidenemiesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidlastattackerlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::preferalliesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyenemies, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidlastdeathlocation, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidsamespawn, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
    var_2 = maps\mp\gametypes\_spawnfactor::score_factor( 0.25, maps\mp\gametypes\_spawnfactor::avoidrecentlyusedbyanyone, var_0 );
    var_0.totalscore = var_0.totalscore + var_2;
}

getspawnpoint_safeguard( var_0 )
{
    var_0 = checkdynamicspawns( var_0 );
    var_1["primary"] = [];
    var_1["secondary"] = [];
    var_1["bad"] = [];

    foreach ( var_3 in var_0 )
    {
        initscoredata( var_3 );
        var_4 = criticalfactors_safeguard( var_3 );
        var_1[var_4][var_1[var_4].size] = var_3;
    }

    if ( var_1["primary"].size )
        return scorespawns_safeguard( var_1["primary"] );

    if ( var_1["secondary"].size )
        return scorespawns_safeguard( var_1["secondary"] );

    logbadspawn( "Buddy Spawn" );
    return selectbestspawnpoint( var_0[0], var_0 );
}

scorespawns_safeguard( var_0 )
{
    var_1 = var_0[0];

    foreach ( var_3 in var_0 )
    {
        scorefactors_safeguard( var_3 );

        if ( var_3.totalscore > var_1.totalscore )
            var_1 = var_3;
    }

    var_1 = selectbestspawnpoint( var_1, var_0 );
    return var_1;
}

criticalfactors_safeguard( var_0 )
{
    return criticalfactors_nearteam( var_0 );
}

scorefactors_safeguard( var_0 )
{
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::randomspawnscore, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 1.0, maps\mp\gametypes\_spawnfactor::preferalliesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
    var_1 = maps\mp\gametypes\_spawnfactor::score_factor( 0.5, maps\mp\gametypes\_spawnfactor::avoidenemiesbydistance, var_0 );
    var_0.totalscore = var_0.totalscore + var_1;
}

logbadspawn( var_0 )
{
    if ( !isdefined( var_0 ) )
        var_0 = "";
    else
        var_0 = "(" + var_0 + ")";

    if ( isdefined( level.matchrecording_logeventmsg ) )
        [[ level.matchrecording_logeventmsg ]]( "LOG_BAD_SPAWN", gettime(), var_0 );
}
