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

main()
{
    thread main_thread();
}

main_thread()
{
    common_scripts\utility::flag_init( "teleport_setup_complete" );
    level.teleport_minimaps = [];
    level.teleport_allowed = 1;
    level.teleport_to_offset = 1;
    level.teleport_to_nodes = 1;
    level.teleport_include_killsteaks = 1;
    level.teleport_gamemode_func = undefined;
    level.teleport_pre_funcs = [];
    level.teleport_post_funcs = [];
    level.teleport_a10_inboundlist = [];
    level.teleport_a10_outboundlist = [];
    level.teleport_nodes_in_zone = [];
    level.teleport_pathnode_zones = [];
    level.teleport_onstartgametype = level.onstartgametype;
    level.onstartgametype = ::teleport_onstartgametype;
    level.teleportgetactivenodesfunc = ::teleport_get_active_nodes;
    level.teleportgetactivepathnodezonesfunc = ::teleport_get_active_pathnode_zones;
}

teleport_init()
{
    level.teleport_spawn_info = [];
    var_0 = common_scripts\utility::getstructarray( "teleport_world_origin", "targetname" );

    if ( !var_0.size )
        return;

    level.teleport_zones = [];

    foreach ( var_2 in var_0 )
    {
        if ( !isdefined( var_2.script_noteworthy ) )
            var_2.script_noteworthy = "zone_" + level.teleport_zones.size;

        var_2.name = var_2.script_noteworthy;
        teleport_parse_zone_targets( var_2 );
        level.teleport_nodes_in_zone[var_2.name] = [];
        level.teleport_pathnode_zones[var_2.name] = [];
        level.teleport_zones[var_2.script_noteworthy] = var_2;
    }

    var_4 = getallnodes();

    foreach ( var_6 in var_4 )
    {
        var_2 = teleport_closest_zone( var_6.origin );
        level.teleport_nodes_in_zone[var_2.name][level.teleport_nodes_in_zone[var_2.name].size] = var_6;
    }

    for ( var_8 = 0; var_8 < getzonecount(); var_8++ )
    {
        var_2 = teleport_closest_zone( getzoneorigin( var_8 ) );
        level.teleport_pathnode_zones[var_2.name][level.teleport_pathnode_zones[var_2.name].size] = var_8;
    }

    if ( !isdefined( level.teleport_zone_current ) )
    {
        if ( isdefined( level.teleport_zones["start"] ) )
            teleport_set_current_zone( "start" );
        else
        {
            foreach ( var_11, var_10 in level.teleport_zones )
            {
                teleport_set_current_zone( var_11 );
                break;
            }
        }
    }

    level.dynamicspawns = ::teleport_filter_spawn_point;
}

teleport_onstartgametype()
{
    teleport_init();
    var_0 = undefined;
    var_1 = undefined;

    switch ( level.gametype )
    {
        case "dom":
            var_1 = ::teleport_onstartgamedom;
            break;
        case "siege":
            var_1 = ::teleport_onstartgamesiege;
            break;
        case "conf":
            var_1 = ::teleport_onstartgameconf;
            break;
        case "sd":
            var_0 = ::teleport_pre_onstartgamesd;
            break;
        case "sr":
            var_0 = ::teleport_pre_onstartgamesr;
            break;
        case "blitz":
            var_0 = ::teleport_pre_onstartgameblitz;
            break;
        case "sotf_ffa":
        case "sotf":
            var_1 = ::teleport_onstartgamesotf;
            break;
        case "grind":
            var_1 = ::teleport_onstartgamegrind;
            break;
        case "horde":
            var_0 = ::teleport_onstartgamehorde;
            break;
        case "dm":
        case "war":
        case "infect":
            break;
        default:
            break;
    }

    if ( isdefined( var_0 ) )
        level [[ var_0 ]]();

    level [[ level.teleport_onstartgametype ]]();

    if ( isdefined( var_1 ) )
        level [[ var_1 ]]();

    common_scripts\utility::flag_set( "teleport_setup_complete" );
}

teleport_pre_onstartgameblitz()
{
    foreach ( var_1 in level.teleport_zones )
        var_1.blitz_all_triggers = [];

    var_3 = getentarray( "axis_portal", "targetname" );

    foreach ( var_5 in var_3 )
    {
        var_6 = teleport_closest_zone( var_5.origin );

        if ( isdefined( var_6 ) )
        {
            var_6.blitz_axis_trigger_origin = var_5.origin;
            var_6.blitz_all_triggers[var_6.blitz_all_triggers.size] = var_5;
            teleport_change_targetname( var_5 );
        }
    }

    var_8 = getentarray( "allies_portal", "targetname" );

    foreach ( var_5 in var_8 )
    {
        var_6 = teleport_closest_zone( var_5.origin );

        if ( isdefined( var_6 ) )
        {
            var_6.blitz_allies_trigger_origin = var_5.origin;
            var_6.blitz_all_triggers[var_6.blitz_all_triggers.size] = var_5;
            teleport_change_targetname( var_5 );
        }
    }

    var_11 = level.teleport_zones[level.teleport_zone_current];
    teleport_restore_targetname( var_11.blitz_all_triggers );
    level.teleport_gamemode_func = ::teleport_onteleportblitz;
}

teleport_onteleportblitz( var_0 )
{
    var_1 = level.teleport_zones[var_0];
    var_2 = level.teleport_zones[level.teleport_zone_current];
    var_3 = "axis";
    var_4 = "allies";

    if ( game["switchedsides"] )
    {
        var_3 = "allies";
        var_4 = "axis";
    }

    var_5 = var_1.blitz_axis_trigger_origin - var_2.blitz_axis_trigger_origin;
    level.portallist[var_3].origin = level.portallist[var_3].origin + var_5;
    level.portallist[var_3].trigger.origin = level.portallist[var_3].trigger.origin + var_5;
    objective_position( level.portallist[var_3].ownerteamid, var_1.blitz_axis_trigger_origin + ( 0, 0, 72 ) );
    objective_position( level.portallist[var_3].enemyteamid, var_1.blitz_axis_trigger_origin + ( 0, 0, 72 ) );
    var_6 = var_1.blitz_allies_trigger_origin - var_2.blitz_allies_trigger_origin;
    level.portallist[var_4].origin = level.portallist[var_4].origin + var_6;
    level.portallist[var_4].trigger.origin = level.portallist[var_4].trigger.origin + var_6;
    objective_position( level.portallist[var_4].ownerteamid, var_1.blitz_allies_trigger_origin + ( 0, 0, 72 ) );
    objective_position( level.portallist[var_4].enemyteamid, var_1.blitz_allies_trigger_origin + ( 0, 0, 72 ) );
    maps\mp\gametypes\blitz::assignteamspawns();

    foreach ( var_8 in level.players )
        var_8 maps\mp\gametypes\blitz::showteamportalfx();
}

teleport_pre_onstartgamesr()
{
    teleport_pre_onstartgamesd_and_sr();
}

teleport_pre_onstartgamesd()
{
    teleport_pre_onstartgamesd_and_sr();
}

teleport_pre_onstartgamesd_and_sr()
{
    foreach ( var_1 in level.teleport_zones )
    {
        var_1.sd_triggers = [];
        var_1.sd_bombs = [];
        var_1.sd_bombzones = [];
    }

    var_3 = getentarray( "sd_bomb_pickup_trig", "targetname" );

    foreach ( var_5 in var_3 )
    {
        var_6 = teleport_closest_zone( var_5.origin );

        if ( isdefined( var_6 ) )
        {
            var_6.sd_triggers[var_6.sd_triggers.size] = var_5;
            teleport_change_targetname( var_5, var_6.name );
        }
    }

    var_8 = getentarray( "sd_bomb", "targetname" );

    foreach ( var_10 in var_8 )
    {
        var_6 = teleport_closest_zone( var_10.origin );

        if ( isdefined( var_6 ) )
        {
            var_6.sd_bombs[var_6.sd_bombs.size] = var_10;
            teleport_change_targetname( var_10, var_6.name );
        }
    }

    var_12 = getentarray( "bombzone", "targetname" );

    foreach ( var_14 in var_12 )
    {
        var_6 = teleport_closest_zone( var_14.origin );

        if ( isdefined( var_6 ) )
        {
            var_6.sd_bombzones[var_6.sd_bombzones.size] = var_14;
            teleport_change_targetname( var_14, var_6.name );
        }
    }

    var_16 = [];

    if ( maps\mp\_utility::isanymlgmatch() )
        var_16[0] = "start";
    else
    {
        foreach ( var_1 in level.teleport_zones )
        {
            if ( var_1.sd_triggers.size && var_1.sd_triggers.size && var_1.sd_triggers.size )
                var_16[var_16.size] = var_1.name;
        }
    }

    teleport_gamemode_disable_teleport( var_16 );
    var_19 = level.teleport_zones[level.teleport_zone_current];
    teleport_restore_targetname( var_19.sd_triggers );
    teleport_restore_targetname( var_19.sd_bombs );
    teleport_restore_targetname( var_19.sd_bombzones );
}

teleport_onstartgamesotf()
{
    foreach ( var_1 in level.teleport_zones )
        var_1.sotf_chest_spawnpoints = [];

    var_3 = common_scripts\utility::getstructarray( "sotf_chest_spawnpoint", "targetname" );

    foreach ( var_5 in var_3 )
    {
        var_6 = teleport_closest_zone( var_5.origin );

        if ( isdefined( var_6 ) )
            var_6.sotf_chest_spawnpoints[var_6.sotf_chest_spawnpoints.size] = var_5;
    }

    var_8 = [];

    foreach ( var_1 in level.teleport_zones )
    {
        if ( var_1.sotf_chest_spawnpoints.size )
            var_8[var_8.size] = var_1.name;
    }

    level.teleport_gamemode_func = ::teleport_onteleportsotf;
    teleport_gamemode_disable_teleport( var_8 );
}

teleport_onteleportsotf( var_0 )
{
    var_1 = level.teleport_zones[var_0];
    level.struct_class_names["targetname"]["sotf_chest_spawnpoint"] = var_1.sotf_chest_spawnpoints;
}

teleport_onstartgamegrind()
{
    foreach ( var_1 in level.teleport_zones )
        var_1.grindzones = [];

    foreach ( var_4 in level.zonelist )
    {
        var_5 = teleport_closest_zone( var_4.origin );

        if ( isdefined( var_5 ) )
        {
            var_4.teleport_zone = var_5.name;
            var_5.grindzones[var_5.grindzones.size] = var_4;
        }
    }

    level.teleport_gamemode_func = ::teleport_onteleportgrind;
    teleport_onteleportgrind( level.teleport_zone_current );
}

teleport_onteleportgrind( var_0 )
{
    var_1 = level.teleport_zones[var_0];

    foreach ( var_3 in var_1.grindzones )
    {
        if ( var_0 != level.teleport_zone_current )
        {
            objective_state( var_3.objid_axis, "active" );
            objective_state( var_3.objid_allies, "active" );

            if ( isdefined( var_3.grind_headicon_allies ) && isdefined( var_3.grind_headicon_allies.old_alpha ) )
                var_3.grind_headicon_allies.alpha = var_3.grind_headicon_allies.old_alpha;

            if ( isdefined( var_3.grind_headicon_axis ) && isdefined( var_3.grind_headicon_axis.old_alpha ) )
                var_3.grind_headicon_axis.alpha = var_3.grind_headicon_axis.old_alpha;
        }
    }

    foreach ( var_9, var_6 in level.teleport_zones )
    {
        foreach ( var_3 in var_6.grindzones )
        {
            if ( var_9 != var_0 )
                thread teleport_hidegrindzone( var_3 );
        }
    }

    foreach ( var_11 in level.dogtags )
    {
        var_11.visual hide();
        var_11.trigger hide();
        var_11 maps\mp\gametypes\_gameobjects::allowuse( "none" );
        var_11 notify( "reset" );
        var_11.lastusedtime = 0;
    }
}

teleport_hidegrindzone( var_0 )
{
    objective_state( var_0.objid_axis, "invisible" );
    objective_state( var_0.objid_allies, "invisible" );

    while ( !isdefined( var_0.grind_headicon_allies ) || !isdefined( var_0.grind_headicon_axis ) )
        common_scripts\utility::waitframe();

    var_0.grind_headicon_allies.old_alpha = var_0.grind_headicon_allies.alpha;
    var_0.grind_headicon_allies.alpha = 0;
    var_0.grind_headicon_axis.old_alpha = var_0.grind_headicon_axis.alpha;
    var_0.grind_headicon_axis.alpha = 0;
}

teleport_onstartgamehorde()
{
    foreach ( var_1 in level.teleport_zones )
        var_1.horde_drops = [];

    var_3 = common_scripts\utility::getstructarray( "horde_drop", "targetname" );

    foreach ( var_5 in var_3 )
    {
        var_6 = teleport_closest_zone( var_5.origin );

        if ( isdefined( var_6 ) )
            var_6.horde_drops[var_6.horde_drops.size] = var_5;
    }

    var_8 = [];

    foreach ( var_1 in level.teleport_zones )
    {
        if ( var_1.horde_drops.size )
            var_8[var_8.size] = var_1.name;
    }

    teleport_gamemode_disable_teleport( var_8 );
    var_11 = level.teleport_zones[level.teleport_zone_current];
    level.struct_class_names["targetname"]["horde_drop"] = var_11.horde_drops;
}

teleport_change_targetname( var_0, var_1 )
{
    if ( !isarray( var_0 ) )
        var_0 = [ var_0 ];

    if ( !isdefined( var_1 ) )
        var_1 = "hide_from_getEnt";

    foreach ( var_3 in var_0 )
    {
        var_3.saved_targetname = var_3.targetname;
        var_3.targetname = var_3.targetname + "_" + var_1;
    }
}

teleport_gamemode_disable_teleport( var_0 )
{
    if ( !isdefined( var_0 ) )
        var_0 = getarraykeys( level.teleport_zones );

    var_1 = game["teleport_zone_dom"];

    if ( !isdefined( var_1 ) )
    {
        var_1 = common_scripts\utility::random( var_0 );
        game["teleport_zone_dom"] = var_1;
    }

    teleport_to_zone( var_1, 0 );
    level.teleport_allowed = 0;
}

teleport_restore_targetname( var_0 )
{
    if ( !isarray( var_0 ) )
        var_0 = [ var_0 ];

    foreach ( var_2 in var_0 )
    {
        if ( isdefined( var_2.saved_targetname ) )
            var_2.targetname = var_2.saved_targetname;
    }
}

teleport_onstartgamedom()
{
    foreach ( var_1 in level.teleport_zones )
    {
        var_1.flags = [];
        var_1.domflags = [];
    }

    level.all_dom_flags = level.flags;

    foreach ( var_4 in level.flags )
    {
        var_5 = teleport_closest_zone( var_4.origin );

        if ( isdefined( var_5 ) )
        {
            var_4.teleport_zone = var_5.name;
            var_5.flags[var_5.flags.size] = var_4;
            var_5.domflags[var_5.domflags.size] = var_4.useobj;
        }
    }

    level.dom_flag_data = [];

    foreach ( var_1 in level.teleport_zones )
    {
        foreach ( var_9 in var_1.flags )
        {
            var_10 = spawnstruct();
            var_10.trigger_origin = var_9.origin;
            var_10.visual_origin = var_9.useobj.visuals[0].origin;
            var_10.baseeffectpos = var_9.useobj.baseeffectpos;
            var_10.baseeffectforward = var_9.useobj.baseeffectforward;
            var_10.baseeffectright = var_9.useobj.baseeffectright;
            var_10.obj_origin = var_9.useobj.curorigin;
            var_10.obj3d_origins = [];

            foreach ( var_12 in level.teamnamelist )
            {
                var_13 = "objpoint_" + var_12 + "_" + var_9.useobj.entnum;
                var_14 = maps\mp\gametypes\_objpoints::getobjpointbyname( var_13 );

                if ( isdefined( var_14 ) )
                    var_10.obj3d_origins[var_12] = ( var_14.x, var_14.y, var_14.z );
            }

            level.dom_flag_data[var_1.name][var_9.useobj.label] = var_10;
        }
    }

    level.flags = level.teleport_zones[level.teleport_zone_current].flags;
    level.domflags = level.teleport_zones[level.teleport_zone_current].domflags;

    foreach ( var_1 in level.teleport_zones )
    {
        foreach ( var_4 in var_1.flags )
        {
            if ( var_1.name == level.teleport_zone_current )
                continue;

            var_4.useobj.visuals[0] delete();
            var_4.useobj maps\mp\gametypes\_gameobjects::deleteuseobject();
        }
    }

    level.teleport_gamemode_func = ::teleport_onteleportdom;
    teleport_onteleportdom( level.teleport_zone_current );
    level.teleport_dom_finished_initializing = 1;
    level thread teleport_dom_post_bot_cleanup();
}

teleport_dom_post_bot_cleanup()
{
    while ( !isdefined( level.bot_gametype_precaching_done ) )
        wait 0.05;

    foreach ( var_1 in level.teleport_zones )
    {
        foreach ( var_3 in var_1.flags )
        {
            var_4 = level.dom_flag_data[var_1.name][var_3.useobj.label];
            var_4.nodes = var_3.nodes;

            if ( var_1.name != level.teleport_zone_current )
                var_3 delete();
        }
    }
}

teleport_onstartgamesiege()
{
    foreach ( var_1 in level.teleport_zones )
    {
        var_1.flags = [];
        var_1.domflags = [];
    }

    level.all_dom_flags = level.flags;

    foreach ( var_4 in level.flags )
    {
        var_5 = teleport_closest_zone( var_4.origin );

        if ( isdefined( var_5 ) )
        {
            var_4.teleport_zone = var_5.name;
            var_5.flags[var_5.flags.size] = var_4;
            var_5.domflags[var_5.domflags.size] = var_4.useobj;
        }
    }

    level.dom_flag_data = [];

    foreach ( var_1 in level.teleport_zones )
    {
        foreach ( var_9 in var_1.flags )
        {
            var_10 = spawnstruct();
            var_10.trigger_origin = var_9.origin;
            var_10.visual_origin = var_9.useobj.visuals[0].origin;
            var_10.baseeffectpos = var_9.useobj.baseeffectpos;
            var_10.baseeffectforward = var_9.useobj.baseeffectforward;
            var_10.baseeffectright = var_9.useobj.baseeffectright;
            var_10.obj_origin = var_9.useobj.curorigin;
            var_10.obj3d_origins = [];

            foreach ( var_12 in level.teamnamelist )
            {
                var_13 = "objpoint_" + var_12 + "_" + var_9.useobj.entnum;
                var_14 = maps\mp\gametypes\_objpoints::getobjpointbyname( var_13 );

                if ( isdefined( var_14 ) )
                    var_10.obj3d_origins[var_12] = ( var_14.x, var_14.y, var_14.z );
            }

            level.dom_flag_data[var_1.name][var_9.useobj.label] = var_10;
        }
    }

    var_18 = "start";
    level.flags = level.teleport_zones[var_18].flags;
    level.domflags = level.teleport_zones[var_18].domflags;

    foreach ( var_1 in level.teleport_zones )
    {
        foreach ( var_4 in var_1.flags )
        {
            if ( var_1.name == var_18 )
                continue;

            var_4.useobj.visuals[0] delete();
            var_4.useobj maps\mp\gametypes\_gameobjects::deleteuseobject();
        }
    }

    game["teleport_zone_dom"] = var_18;
    teleport_gamemode_disable_teleport();
    teleport_onteleportsiege( var_18 );
}

teleport_onstartgameconf()
{
    level.teleport_gamemode_func = ::teleport_onteleportconf;
}

teleport_onteleportdom( var_0 )
{
    var_1 = level.teleport_zones[level.teleport_zone_current];
    var_2 = level.teleport_zones[var_0];

    if ( var_0 == level.teleport_zone_current )
        return;

    foreach ( var_4 in level.flags )
    {
        var_5 = level.dom_flag_data[var_0][var_4.useobj.label];
        var_4.origin = var_5.trigger_origin;
        var_4.useobj.visuals[0].origin = var_5.visual_origin;
        var_4.useobj.baseeffectpos = var_5.baseeffectpos;
        var_4.useobj.baseeffectforward = var_5.baseeffectforward;
        var_4.useobj maps\mp\gametypes\dom::resetflagbaseeffect();
        var_4.teleport_zone = var_0;
        var_4.nodes = var_5.nodes;

        foreach ( var_8, var_7 in var_4.useobj.teamobjids )
            objective_position( var_7, var_5.obj_origin );

        foreach ( var_10 in level.teamnamelist )
        {
            var_11 = "objpoint_" + var_10 + "_" + var_4.useobj.entnum;
            var_12 = maps\mp\gametypes\_objpoints::getobjpointbyname( var_11 );
            var_12.x = var_5.obj3d_origins[var_10][0];
            var_12.y = var_5.obj3d_origins[var_10][1];
            var_12.z = var_5.obj3d_origins[var_10][2];
        }
    }
}

teleport_onteleportsiege( var_0 )
{
    foreach ( var_2 in level.flags )
    {
        var_3 = level.dom_flag_data[var_0][var_2.useobj.label];
        var_2.origin = var_3.trigger_origin;
        var_2.useobj.visuals[0].origin = var_3.visual_origin;
        var_2.useobj.baseeffectpos = var_3.baseeffectpos;
        var_2.useobj.baseeffectforward = var_3.baseeffectforward;
        var_2.useobj maps\mp\gametypes\dom::resetflagbaseeffect();
        var_2.teleport_zone = var_0;
        var_2.nodes = var_3.nodes;

        foreach ( var_6, var_5 in var_2.useobj.teamobjids )
            objective_position( var_5, var_3.obj_origin );

        foreach ( var_8 in level.teamnamelist )
        {
            var_9 = "objpoint_" + var_8 + "_" + var_2.useobj.entnum;
            var_10 = maps\mp\gametypes\_objpoints::getobjpointbyname( var_9 );
            var_10.x = var_3.obj3d_origins[var_8][0];
            var_10.y = var_3.obj3d_origins[var_8][1];
            var_10.z = var_3.obj3d_origins[var_8][2];
        }
    }
}

teleport_get_matching_dom_flag( var_0, var_1 )
{
    foreach ( var_3 in level.teleport_zones[var_1].flags )
    {
        if ( var_0.useobj.label == var_3.useobj.label )
            return var_3;
    }

    return undefined;
}

teleport_onteleportconf( var_0 )
{
    var_1 = get_teleport_delta( var_0 );

    foreach ( var_3 in level.dogtags )
    {
        var_4 = var_3.curorigin + var_1;
        var_5 = teleport_get_safe_node_near( var_4 );

        if ( isdefined( var_5 ) )
        {
            var_5.last_teleport_time = gettime();
            var_6 = var_5.origin - var_3.curorigin;
            var_3.curorigin = var_3.curorigin + var_6;
            var_3.trigger.origin = var_3.trigger.origin + var_6;
            var_3.visuals[0].origin = var_3.visuals[0].origin + var_6;
            var_3.visuals[1].origin = var_3.visuals[1].origin + var_6;
            continue;
        }

        var_3 maps\mp\gametypes\conf::resettags();
    }
}

teleport_get_safe_node_near( var_0 )
{
    var_1 = gettime();
    var_2 = getnodesinradiussorted( var_0, 300, 0, 200, "Path" );

    for ( var_3 = 0; var_3 < var_2.size; var_3++ )
    {
        var_4 = var_2[var_3];

        if ( isdefined( var_4.last_teleport_time ) && var_4.last_teleport_time == var_1 )
            continue;

        return var_4;
    }

    return undefined;
}

teleport_closest_zone( var_0 )
{
    var_1 = undefined;
    var_2 = undefined;

    foreach ( var_4 in level.teleport_zones )
    {
        var_5 = distancesquared( var_4.origin, var_0 );

        if ( !isdefined( var_1 ) || var_5 < var_1 )
        {
            var_1 = var_5;
            var_2 = var_4;
        }
    }

    return var_2;
}

teleport_origin_use_nodes( var_0 )
{
    level.teleport_to_nodes = var_0;
}

teleport_origin_use_offset( var_0 )
{
    level.teleport_to_offset = var_0;
}

teleport_include_killstreaks( var_0 )
{
    level.teleport_include_killsteaks = var_0;
}

teleport_set_minimap_for_zone( var_0, var_1 )
{
    level.teleport_minimaps[var_0] = var_1;
}

teleport_set_pre_func( var_0, var_1 )
{
    level.teleport_pre_funcs[var_1] = var_0;
}

teleport_set_post_func( var_0, var_1 )
{
    level.teleport_post_funcs[var_1] = var_0;
}

teleport_set_a10_splines_for_zone( var_0, var_1, var_2 )
{
    level.teleport_a10_inboundlist[var_0] = var_1;
    level.teleport_a10_outboundlist[var_0] = var_2;
}

teleport_parse_zone_targets( var_0 )
{
    if ( isdefined( var_0.origins_pasrsed ) && var_0.origins_pasrsed )
        return;

    var_0.teleport_origins = [];
    var_0.teleport_origins["none"] = [];
    var_0.teleport_origins["allies"] = [];
    var_0.teleport_origins["axis"] = [];
    var_1 = common_scripts\utility::getstructarray( "teleport_zone_" + var_0.name, "targetname" );

    if ( isdefined( var_0.target ) )
    {
        var_2 = common_scripts\utility::getstructarray( var_0.target, "targetname" );
        var_1 = common_scripts\utility::array_combine( var_2, var_1 );
    }

    foreach ( var_4 in var_1 )
    {
        if ( !isdefined( var_4.script_noteworthy ) )
            var_4.script_noteworthy = "teleport_origin";

        switch ( var_4.script_noteworthy )
        {
            case "teleport_origin":
                var_5 = var_4.origin + ( 0, 0, 1 );
                var_6 = var_4.origin - ( 0, 0, 250 );
                var_7 = bullettrace( var_5, var_6, 0 );

                if ( var_7["fraction"] == 1.0 )
                    break;

                var_4.origin = var_7["position"];
            case "telport_origin_nodrop":
                if ( !isdefined( var_4.script_parameters ) )
                    var_4.script_parameters = "none,axis,allies";

                var_8 = strtok( var_4.script_parameters, ", " );

                foreach ( var_10 in var_8 )
                {
                    if ( !isdefined( var_0.teleport_origins[var_10] ) )
                        continue;

                    if ( !isdefined( var_4.angles ) )
                        var_4.angles = ( 0, 0, 0 );

                    var_11 = var_0.teleport_origins[var_10].size;
                    var_0.teleport_origins[var_10][var_11] = var_4;
                }

                break;
            default:
                break;
        }
    }

    var_0.origins_pasrsed = 1;
}

teleport_set_current_zone( var_0 )
{
    level.teleport_zone_current = var_0;

    if ( isdefined( level.teleport_minimaps[var_0] ) )
        maps\mp\_compass::setupminimap( level.teleport_minimaps[var_0] );
}

teleport_filter_spawn_point( var_0, var_1 )
{
    if ( !isdefined( var_1 ) )
        var_1 = level.teleport_zone_current;

    var_2 = [];

    foreach ( var_4 in var_0 )
    {
        if ( !isdefined( var_4.index ) )
            var_4.index = "ent_" + var_4 getentitynumber();

        if ( !isdefined( level.teleport_spawn_info[var_4.index] ) )
            teleport_init_spawn_info( var_4 );

        if ( level.teleport_spawn_info[var_4.index].zone == var_1 )
            var_2[var_2.size] = var_4;
    }

    return var_2;
}

teleport_init_spawn_info( var_0 )
{
    if ( isdefined( level.teleport_spawn_info[var_0.index] ) )
        return;

    var_1 = spawnstruct();
    var_1.spawner = var_0;
    var_2 = undefined;

    foreach ( var_4 in level.teleport_zones )
    {
        var_5 = distance( var_4.origin, var_0.origin );

        if ( !isdefined( var_2 ) || var_5 < var_2 )
        {
            var_2 = var_5;
            var_1.zone = var_4.name;
        }
    }

    level.teleport_spawn_info[var_0.index] = var_1;
}

teleport_is_valid_zone( var_0 )
{
    foreach ( var_3, var_2 in level.teleport_zones )
    {
        if ( var_3 == var_0 )
            return 1;
    }

    return 0;
}

teleport_to_zone( var_0, var_1 )
{
    if ( !level.teleport_allowed )
        return;

    if ( !isdefined( var_1 ) )
        var_1 = 1;

    var_2 = level.teleport_pre_funcs[var_0];

    if ( isdefined( var_2 ) && var_1 )
        [[ var_2 ]]();

    var_3 = level.teleport_zones[level.teleport_zone_current];
    var_4 = level.teleport_zones[var_0];

    if ( !isdefined( var_3 ) || !isdefined( var_4 ) )
        return;

    teleport_to_zone_players( var_0 );
    teleport_to_zone_agents( var_0 );

    if ( level.teleport_include_killsteaks )
        teleport_to_zone_killstreaks( var_0 );

    if ( isdefined( level.teleport_gamemode_func ) )
        [[ level.teleport_gamemode_func ]]( var_0 );

    teleport_set_current_zone( var_0 );
    level notify( "teleport_to_zone", var_0 );
    var_5 = level.teleport_post_funcs[var_0];

    if ( isdefined( var_5 ) && var_1 )
        [[ var_5 ]]();

    if ( isdefined( level.bot_funcs ) && isdefined( level.bot_funcs["post_teleport"] ) )
        [[ level.bot_funcs["post_teleport"] ]]();
}

teleport_to_zone_agents( var_0 )
{
    var_1 = maps\mp\agents\_agent_utility::getactiveagentsoftype( "all" );

    foreach ( var_3 in var_1 )
        teleport_to_zone_character( var_0, var_3 );
}

teleport_to_zone_players( var_0 )
{
    foreach ( var_2 in level.players )
        teleport_to_zone_character( var_0, var_2 );
}

teleport_to_zone_character( var_0, var_1 )
{
    var_2 = level.teleport_zones[level.teleport_zone_current];
    var_3 = level.teleport_zones[var_0];
    var_4 = gettime();

    if ( isplayer( var_1 ) && ( var_1.sessionstate == "intermission" || var_1.sessionstate == "spectator" ) )
    {
        var_5 = getentarray( "mp_global_intermission", "classname" );
        var_5 = teleport_filter_spawn_point( var_5, var_0 );
        var_6 = var_5[0];
        var_1 dontinterpolate();
        var_1 setorigin( var_6.origin );
        var_1 setplayerangles( var_6.angles );
    }
    else
    {
        var_7 = undefined;
        var_8 = var_1.angles;

        if ( isplayer( var_1 ) )
            var_8 = var_1 getplayerangles();

        foreach ( var_14, var_10 in var_3.teleport_origins )
        {
            var_3.teleport_origins[var_14] = common_scripts\utility::array_randomize( var_10 );

            foreach ( var_12 in var_10 )
                var_12.claimed = 0;
        }

        var_15 = [];

        if ( level.teambased )
        {
            if ( isdefined( var_1.team ) && isdefined( var_3.teleport_origins[var_1.team] ) )
                var_15 = var_3.teleport_origins[var_1.team];
        }
        else
            var_15 = var_3.teleport_origins["none"];

        foreach ( var_12 in var_15 )
        {
            if ( !var_12.claimed )
            {
                var_7 = var_12.origin;
                var_8 = var_12.angles;
                var_12.claimed = 1;
                break;
            }
        }

        var_18 = var_3.origin - var_2.origin;
        var_19 = var_1.origin + var_18;

        if ( !isdefined( var_7 ) && level.teleport_to_offset )
        {
            if ( canspawn( var_19 ) && !positionwouldtelefrag( var_19 ) )
                var_7 = var_19;
        }

        if ( !isdefined( var_7 ) && level.teleport_to_nodes )
        {
            var_20 = getnodesinradiussorted( var_19, 300, 0, 200, "Path" );

            for ( var_21 = 0; var_21 < var_20.size; var_21++ )
            {
                var_22 = var_20[var_21];

                if ( isdefined( var_22.last_teleport_time ) && var_22.last_teleport_time == var_4 )
                    continue;

                var_12 = var_22.origin;

                if ( canspawn( var_12 ) && !positionwouldtelefrag( var_12 ) )
                {
                    var_22.last_teleport_time = var_4;
                    var_7 = var_12;
                    break;
                }
            }
        }

        if ( !isdefined( var_7 ) )
        {
            var_1 maps\mp\_utility::_suicide();
            return;
        }

        var_1 cancelmantle();
        var_1 dontinterpolate();
        var_1 setorigin( var_7 );
        var_1 setplayerangles( var_8 );
        thread teleport_validate_success( var_1 );
    }
}

teleport_validate_success( var_0 )
{
    level waittill( "teleport_to_zone" );

    if ( isdefined( var_0 ) )
    {
        var_1 = teleport_closest_zone( var_0.origin );

        if ( var_1.name != level.teleport_zone_current )
            var_0 maps\mp\_utility::_suicide();
    }
}

get_teleport_delta( var_0 )
{
    var_1 = level.teleport_zones[var_0];
    var_2 = level.teleport_zones[level.teleport_zone_current];
    var_3 = var_1.origin - var_2.origin;
    return var_3;
}

teleport_to_zone_killstreaks( var_0 )
{
    var_1 = get_teleport_delta( var_0 );
    teleport_add_delta( level.ac130, var_1 );
    array_levelthread_safe( level.heli_start_nodes, ::teleport_add_delta_targets, var_1 );
    array_levelthread_safe( level.heli_loop_nodes, ::teleport_add_delta_targets, var_1 );
    array_levelthread_safe( level.heli_loop_nodes2, ::teleport_add_delta_targets, var_1 );
    array_levelthread_safe( level.strafe_nodes, ::teleport_add_delta_targets, var_1 );
    array_levelthread_safe( level.heli_leave_nodes, ::teleport_add_delta_targets, var_1 );
    array_levelthread_safe( level.heli_crash_nodes, ::teleport_add_delta_targets, var_1 );

    if ( isdefined( level.chopper ) )
    {
        level.chopper.largeprojectiledamage = 1;
        level.chopper notify( "death" );
    }

    teleport_add_delta( level.uavrig, var_1 );
    teleport_add_delta( level.remote_mortar, var_1 );
    teleport_add_delta( level.heli_pilot_mesh, var_1 );
    array_thread_safe( level.air_start_nodes, ::teleport_self_add_delta, var_1 );

    foreach ( var_3 in level.air_start_nodes )
        array_thread_safe( var_3.neighbors, ::teleport_self_add_delta, var_1 );

    array_thread_safe( level.air_node_mesh, ::teleport_self_add_delta, var_1 );

    foreach ( var_3 in level.air_node_mesh )
        array_thread_safe( var_3.neighbors, ::teleport_self_add_delta, var_1 );

    array_thread_safe( level.littlebirds, ::teleport_notify_death );
    teleport_add_delta( level.lbsniper, var_1 );
    var_7 = getent( "airstrikeheight", "targetname" );
    teleport_add_delta( var_7, var_1 );
    var_8 = getentarray( "mp_airsupport", "classname" );
    array_thread_safe( var_8, ::teleport_self_add_delta, var_1 );
    var_9 = getentarray( "heli_attack_area", "targetname" );
    array_thread_safe( var_9, ::teleport_self_add_delta, var_1 );
    array_thread_safe( level.lasedstrikeents, ::teleport_self_add_delta, var_1 );
    var_10 = getent( "remote_uav_range", "targetname" );
    teleport_add_delta( var_10, var_1 );

    foreach ( var_12 in level.participants )
    {
        if ( isdefined( var_12.balldrone ) )
            var_12.balldrone teleport_notify_death();
    }

    if ( isdefined( level.uplinks ) )
    {
        foreach ( var_15 in level.uplinks )
            var_15 notify( "death" );
    }

    var_17 = getentarray( "remoteMissileSpawn", "targetname" );
    array_thread_safe( var_17, ::teleport_self_add_delta, var_1 );

    foreach ( var_19 in var_17 )
    {
        if ( isdefined( var_19.target ) )
            var_19.targetent = getent( var_19.target, "targetname" );

        if ( isdefined( var_19.targetent ) )
            teleport_add_delta( var_19.targetent, var_1 );
    }

    foreach ( var_22 in level.ims )
    {
        var_22 notify( "death" );
        teleport_add_delta( var_22, var_1 );

        if ( !teleport_place_on_ground( var_22 ) )
            var_22 delete();
    }

    foreach ( var_25 in level.turrets )
    {
        var_25 notify( "death" );
        teleport_add_delta( var_25, var_1 );

        if ( !teleport_place_on_ground( var_25 ) )
            var_25 delete();
    }

    var_27 = teleport_get_care_packages();

    foreach ( var_29 in var_27 )
        var_29 maps\mp\killstreaks\_airdrop::deletecrate();

    var_31 = teleport_get_deployable_boxes();

    foreach ( var_33 in var_31 )
        var_33 teleport_notify_death();

    foreach ( var_36 in level.remote_uav )
        var_36 teleport_notify_death();

    var_38 = vehicle_getarray();

    foreach ( var_40 in var_38 )
    {
        if ( isdefined( var_40.model ) && var_40.model == "vehicle_odin_mp" )
            var_40 teleport_notify_death();
    }

    if ( isdefined( level.teleport_a10_inboundlist[var_0] ) )
        level.a10splinesin = level.teleport_a10_inboundlist[var_0];

    if ( isdefined( level.teleport_a10_outboundlist[var_0] ) )
        level.a10splinesout = level.teleport_a10_outboundlist[var_0];

    if ( isdefined( level.intelent ) )
        level.intelent["dropped_time"] = -60000;
}

teleport_notify_death()
{
    if ( isdefined( self ) )
        self notify( "death" );
}

array_thread_safe( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9, var_10 )
{
    if ( !isdefined( var_0 ) )
        return;

    common_scripts\utility::array_thread( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9, var_10 );
}

array_levelthread_safe( var_0, var_1, var_2, var_3, var_4 )
{
    if ( !isdefined( var_0 ) )
        return;

    common_scripts\utility::array_levelthread( var_0, var_1, var_2, var_3, var_4 );
}

teleport_get_care_packages()
{
    return getentarray( "care_package", "targetname" );
}

teleport_get_deployable_boxes()
{
    var_0 = [];
    var_1 = getentarray( "script_model", "classname" );

    foreach ( var_3 in var_1 )
    {
        if ( isdefined( var_3.boxtype ) )
            var_0[var_0.size] = var_3;
    }

    return var_0;
}

teleport_place_on_ground( var_0, var_1 )
{
    if ( !isdefined( var_0 ) )
        return;

    if ( !isdefined( var_1 ) )
        var_1 = 300;

    var_2 = var_0.origin;
    var_3 = var_0.origin - ( 0, 0, var_1 );
    var_4 = bullettrace( var_2, var_3, 0, var_0 );

    if ( var_4["fraction"] < 1 )
    {
        var_0.origin = var_4["position"];
        return 1;
    }
    else
        return 0;
}

teleport_add_delta_targets( var_0, var_1 )
{
    if ( teleport_delta_this_frame( var_0 ) )
        return;

    teleport_add_delta( var_0, var_1 );

    if ( isdefined( var_0.target ) )
    {
        var_2 = getentarray( var_0.target, "targetname" );
        var_3 = common_scripts\utility::getstructarray( var_0.target, "targetname" );
        var_4 = common_scripts\utility::array_combine( var_2, var_3 );
        common_scripts\utility::array_levelthread( var_4, ::teleport_add_delta_targets, var_1 );
    }
}

teleport_self_add_delta_targets( var_0 )
{
    teleport_add_delta_targets( self, var_0 );
}

teleport_self_add_delta( var_0 )
{
    teleport_add_delta( self, var_0 );
}

teleport_add_delta( var_0, var_1 )
{
    if ( isdefined( var_0 ) )
    {
        if ( !teleport_delta_this_frame( var_0 ) )
        {
            var_0.origin = var_0.origin + var_1;
            var_0.last_teleport_time = gettime();
        }
    }
}

teleport_delta_this_frame( var_0 )
{
    return isdefined( var_0.last_teleport_time ) && var_0.last_teleport_time == gettime();
}

teleport_get_active_nodes()
{
    return level.teleport_nodes_in_zone[level.teleport_zone_current];
}

teleport_get_active_pathnode_zones()
{
    return level.teleport_pathnode_zones[level.teleport_zone_current];
}
