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

main()
{
    maps\mp\mp_prisonbreak_precache::main();
    maps\createart\mp_prisonbreak_art::main();
    maps\mp\mp_prisonbreak_fx::main();
    level thread log_piles();
    maps\mp\_load::main();
    maps\mp\_compass::setupminimap( "compass_map_mp_prisonbreak" );
    setdvar( "r_reactiveMotionWindAmplitudeScale", 0.3 );
    setdvar( "r_reactiveMotionWindFrequencyScale", 0.5 );
    setdvar( "r_lightGridEnableTweaks", 1 );
    setdvar( "r_lightGridIntensity", 1.33 );
    maps\mp\_utility::setdvar_cg_ng( "r_diffusecolorscale", 1.5, 1.8 );
    maps\mp\_utility::setdvar_cg_ng( "r_specularcolorscale", 3.0, 6.0 );
    setdvar( "r_ssaofadedepth", 1089 );
    setdvar( "r_ssaorejectdepth", 1200 );

    if ( level.ps3 )
        setdvar( "sm_sunShadowScale", "0.6" );
    else if ( level.xenon )
        setdvar( "sm_sunShadowScale", "0.7" );

    if ( level.ps4 )
        setdvar( "sm_sunSampleSizeNear", 0.33 );
    else if ( level.xb3 )
        setdvar( "sm_sunSampleSizeNear", 0.38 );

    game["attackers"] = "allies";
    game["defenders"] = "axis";

    if ( level.gametype == "sd" || level.gametype == "sr" )
    {
        level.srkillcamoverrideposition = [];
        level.srkillcamoverrideposition["_a"] = ( -1158, 952, 1139 );
        level thread setonbombtimerend();
    }

    level thread tree_bridges();
    level thread falling_rocks();
    level thread initpatchmodels();
}

initpatchmodels()
{
    var_0 = spawn( "script_model", ( -74, 120, 1038 ) );
    var_0 setmodel( "defaultvehicle" );
    var_0.angles = ( 359.24, 258.983, -8.0374 );
    var_1 = getent( "clip128x128x128", "targetname" );
    var_2 = spawn( "script_model", ( 1112, 1859.07, 949.574 ) );
    var_2.angles = ( 0, 325, 45 );
    var_2 clonebrushmodeltoscriptmodel( var_1 );
}

setonbombtimerend()
{
    level endon( "game_ended" );
    level.sd_onbombtimerend = ::onbombtimerend;
    level waittill( "bomb_planted", var_0 );

    if ( var_0 maps\mp\gametypes\_gameobjects::getlabel() == "_b" )
        level.sd_onbombtimerend = undefined;
}

onbombtimerend()
{
    var_0 = getent( "prisondoor1", "targetname" );
    var_1 = getent( "prisondoor2", "targetname" );
    var_0 rotateyaw( -70, 0.5 );
    var_0 playsound( "scn_prison_gate_right" );
    var_1 rotateyaw( 70, 0.5 );
    var_0 playsound( "scn_prison_gate_left" );
    wait 1;
    level notify( "sd_free_prisoners" );
}

initprisoners()
{
    initprisonerloadout();
    level.sd_prisonerobjective = getent( "sd_prisonerObjective", "targetname" );
    wait 3;
    level.bot_funcs["think"] = maps\mp\gametypes\_globallogic::blank;
    var_0 = getentarray( "mp_spawn", "classname" );

    foreach ( var_2 in var_0 )
        level thread createprisoner( var_2 );
}

createprisoner( var_0 )
{
    var_1 = addtestclient();
    var_1.pers["isBot"] = 1;
    var_1.equipment_enabled = 1;
    var_1.bot_team = game["attackers"];

    while ( !isdefined( var_1.pers["team"] ) )
        wait 0.05;

    var_1 notify( "menuresponse", game["menu_team"], game["attackers"] );
    wait 0.5;
    var_1.pers["gamemodeLoadout"] = level.sd_loadouts["prisoner"];
    var_0.playerspawnpos = var_0.origin;
    var_0.notti = 1;
    var_1.setspawnpoint = var_0;
    var_1 notify( "menuresponse", "changeclass", "gamemode" );
    var_1 thread holdprisoner();
}

holdprisoner()
{
    level endon( "game_ended" );
    self endon( "disconnect" );
    self waittill( "spawned_player" );
    maps\mp\_utility::gameflagwait( "prematch_done" );
    common_scripts\utility::_disableweapon();
    var_0 = spawn( "script_origin", self.origin );
    self playerlinkto( var_0 );
    level waittill( "sd_free_prisoners" );
    self unlink();
    var_0 delete();

    for (;;)
    {
        self botclearscriptgoal();
        self botsetscriptgoal( level.sd_prisonerobjective.origin, 64, "critical" );
        var_1 = common_scripts\utility::waittill_any_return( "goal", "bad_path" );

        if ( var_1 == "goal" )
            break;

        wait 0.05;
    }
}

initprisonerloadout()
{
    level.sd_loadouts["prisoner"]["loadoutPrimary"] = "none";
    level.sd_loadouts["prisoner"]["loadoutPrimaryAttachment"] = "none";
    level.sd_loadouts["prisoner"]["loadoutPrimaryAttachment2"] = "none";
    level.sd_loadouts["prisoner"]["loadoutPrimaryBuff"] = "specialty_null";
    level.sd_loadouts["prisoner"]["loadoutPrimaryCamo"] = "none";
    level.sd_loadouts["prisoner"]["loadoutPrimaryReticle"] = "none";
    level.sd_loadouts["prisoner"]["loadoutSecondary"] = "none";
    level.sd_loadouts["prisoner"]["loadoutSecondaryAttachment"] = "none";
    level.sd_loadouts["prisoner"]["loadoutSecondaryAttachment2"] = "none";
    level.sd_loadouts["prisoner"]["loadoutSecondaryBuff"] = "specialty_null";
    level.sd_loadouts["prisoner"]["loadoutSecondaryCamo"] = "none";
    level.sd_loadouts["prisoner"]["loadoutSecondaryReticle"] = "none";
    level.sd_loadouts["prisoner"]["loadoutEquipment"] = "specialty_null";
    level.sd_loadouts["prisoner"]["loadoutOffhand"] = "none";
    level.sd_loadouts["prisoner"]["loadoutPerk1"] = "specialty_null";
    level.sd_loadouts["prisoner"]["loadoutPerk2"] = "specialty_null";
    level.sd_loadouts["prisoner"]["loadoutPerk3"] = "specialty_null";
    level.sd_loadouts["prisoner"]["loadoutStreakType"] = "assault";
    level.sd_loadouts["prisoner"]["loadoutKillstreak1"] = "none";
    level.sd_loadouts["prisoner"]["loadoutKillstreak2"] = "none";
    level.sd_loadouts["prisoner"]["loadoutKillstreak3"] = "none";
    level.sd_loadouts["prisoner"]["loadoutDeathstreak"] = "specialty_null";
    level.sd_loadouts["prisoner"]["loadoutJuggernaut"] = 0;
}

initinsertionvehicles()
{
    level.sd_insertionvehicles = [];
    var_0 = getentarray( "sd_vehStart", "targetname" );

    foreach ( var_2 in var_0 )
    {
        var_3 = spawn( "script_model", var_2.origin );
        var_3.origin = var_2.origin;
        var_3.angles = var_2.angles;
        var_3 setmodel( "vehicle_hummer_open_top_noturret" );
        var_4 = [];
        var_5 = getent( var_2.target, "targetname" );

        while ( isdefined( var_5 ) )
        {
            var_4[var_4.size] = var_5;

            if ( isdefined( var_5.target ) )
            {
                var_5 = getent( var_5.target, "targetname" );
                continue;
            }

            break;
        }

        level.sd_insertionvehicles[var_2.script_count] = spawnstruct();
        level.sd_insertionvehicles[var_2.script_count].index = var_2.script_count;
        level.sd_insertionvehicles[var_2.script_count].vehicle = var_3;
        level.sd_insertionvehicles[var_2.script_count].start = var_2;
        level.sd_insertionvehicles[var_2.script_count].path = var_4;
        level.sd_insertionvehicles[var_2.script_count].driver = 0;
        level.sd_insertionvehicles[var_2.script_count].passenger = 0;
        level.sd_insertionvehicles[var_2.script_count].arrived = 0;
    }

    level.sd_insertionstarted = undefined;
}

onattackerspawn()
{
    level endon( "game_ended" );

    for (;;)
    {
        level waittill( "player_spawned", var_0 );

        if ( game["state"] != "postgame" && var_0.pers["team"] == game["attackers"] )
            var_0 thread attackerride();
    }
}

attackerride()
{
    level endon( "game_ended" );
    self endon( "death" );
    self endon( "disconnect" );
    common_scripts\utility::_disableweapon();

    if ( !isdefined( level.sd_insertionstarted ) )
    {
        level.sd_insertionstarted = 1;
        level thread startinsertionvehicles();
    }

    var_0 = -1;
    var_1 = 0;
    var_2 = "";
    var_3 = undefined;

    for ( var_4 = 0; var_4 < level.sd_insertionvehicles.size; var_4++ )
    {
        var_3 = level.sd_insertionvehicles[var_4].vehicle;

        if ( !level.sd_insertionvehicles[var_4].driver )
        {
            var_0 = var_4;
            var_1 = 1;
            level.sd_insertionvehicles[var_4].driver = 1;
            self playerlinktodelta( var_3, "tag_driver", 1, 30, 30, 30, 30, 1 );
            self setstance( "crouch" );

            if ( var_4 == 2 )
                var_2 = "tag_walker3";
            else
                var_2 = "tag_walker0";

            break;
        }
        else if ( !level.sd_insertionvehicles[var_4].passenger )
        {
            var_0 = var_4;
            level.sd_insertionvehicles[var_4].passenger = 1;
            self playerlinktodelta( var_3, "tag_passenger", 1, 30, 30, 30, 30, 1 );
            self setstance( "crouch" );

            if ( var_4 == 2 )
                var_2 = "tag_walker1";
            else
                var_2 = "tag_walker2";

            break;
        }
    }

    if ( var_0 < 0 )
    {

    }

    wait 0.05;

    while ( !level.sd_insertionvehicles[var_0].arrived )
        wait 0.05;

    self unlink();
    self setstance( "stand" );
    var_5 = spawn( "script_model", self.origin );
    var_5.origin = self.origin;
    var_5.angles = self.angles;
    var_5 setmodel( "tag_player" );
    self playerlinktodelta( var_5, "tag_player", 1, 30, 30, 30, 30, 1 );
    var_6 = var_3 gettagorigin( var_2 );
    var_7 = var_3 gettagangles( var_2 );
    var_8 = distance( var_5.origin, var_6 ) / 100;
    var_5 moveto( var_6, var_8, var_8 / 2, var_8 / 2 );
    var_5 rotateto( var_7, var_8, var_8 / 2, var_8 / 2 );
    wait( var_8 );
    self unlink();
    var_5 delete();
    common_scripts\utility::_enableweapon();

    if ( var_1 )
        level.sd_insertionvehicles[var_0].driver = 0;
    else
        level.sd_insertionvehicles[var_0].passenger = 0;
}

startinsertionvehicles()
{
    level endon( "game_ended" );

    for ( var_0 = 0; var_0 < level.sd_insertionvehicles.size; var_0++ )
    {
        level thread vehiclemove( var_0 );
        wait 0.3;
    }
}

vehiclemove( var_0 )
{
    level endon( "game_ended" );
    maps\mp\_utility::gameflagwait( "prematch_done" );
    var_1 = level.sd_insertionvehicles[var_0].vehicle;
    var_2 = level.sd_insertionvehicles[var_0].path;

    for ( var_3 = 0; var_3 < var_2.size; var_3++ )
    {
        var_4 = distance( var_1.origin, var_2[var_3].origin ) / 550;
        var_5 = 0;
        var_6 = 0;

        if ( var_3 == 0 )
            var_5 = var_4 / 2;
        else if ( var_3 == var_2.size - 1 )
            var_6 = var_4 / 2;

        var_1 moveto( var_2[var_3].origin, var_4, var_5, var_6 );
        var_1 rotateto( var_2[var_3].angles, var_4 );
        wait( var_4 );
    }

    level.sd_insertionvehicles[var_0].arrived = 1;
}

normalize_angles_180( var_0 )
{
    return ( angle_180( var_0[0] ), angle_180( var_0[1] ), angle_180( var_0[2] ) );
}

angle_180( var_0 )
{
    while ( var_0 > 180 )
        var_0 = var_0 - 360;

    while ( var_0 < -180 )
        var_0 = var_0 + 360;

    return var_0;
}

is_explosive( var_0 )
{
    if ( !isdefined( var_0 ) )
        return 0;

    var_0 = tolower( var_0 );

    switch ( var_0 )
    {
        case "splash":
        case "mod_explosive":
        case "mod_projectile_splash":
        case "mod_grenade_splash":
            return 1;
        default:
            return 0;
    }

    return 0;
}

trap_init( var_0 )
{
    if ( getdvar( "r_reflectionProbeGenerate" ) == "1" )
        return;

    if ( !isdefined( var_0 ) )
        var_0 = 0;

    var_1 = getentarray( self.target, "targetname" );

    foreach ( var_3 in var_1 )
    {
        if ( !isdefined( var_3.script_noteworthy ) )
            continue;

        switch ( var_3.script_noteworthy )
        {
            case "activate_trigger":
                if ( var_0 )
                    var_3 delete();
                else
                    self.activate_trigger = var_3;

                break;
            case "use_model":
                if ( var_0 )
                    var_3 delete();
                else
                    self.use_model = var_3;

                break;
            case "use_trigger":
                if ( var_0 )
                    var_3 delete();
                else
                    self.use_trigger = var_3;

                break;
            default:
                break;
        }
    }

    if ( isdefined( self.activate_trigger ) && isdefined( self.use_model ) && isdefined( self.use_trigger ) )
    {
        thread trap_use_watch();
        thread trap_delete_visuals();
    }
}

trap_delete_visuals()
{
    self waittill( "trap_activated" );

    foreach ( var_1 in self.useobject.visuals )
        var_1 delete();

    self.useobject.visuals = [];
    trap_set_can_use( 0 );
}

trap_use_watch()
{
    wait 0.05;
    self.useobject = maps\mp\gametypes\_gameobjects::createuseobject( "neutral", self.use_trigger, [ self.use_model ], ( 0, 0, 0 ) );
    self.useobject.parent = self;
    trap_set_can_use( 1 );
    self.useobject maps\mp\gametypes\_gameobjects::setusetime( 2.5 );
    self.useobject maps\mp\gametypes\_gameobjects::setusetext( &"MP_SETTING_TRAP" );
    self.useobject maps\mp\gametypes\_gameobjects::setusehinttext( &"MP_SET_TRAP" );
    self.useobject maps\mp\gametypes\_gameobjects::setvisibleteam( "any" );
    self.useobject.onuse = ::trap_onuse;
}

trap_set_can_use( var_0 )
{
    if ( var_0 )
    {
        if ( isdefined( self.use_icon_angles ) && isdefined( self.use_icon_origin ) )
            thread hand_icon( "use", self.use_icon_origin, self.use_icon_angles, "trap_triggered" );

        if ( isdefined( self.useobject ) && isdefined( self.useobject.visuals ) )
        {
            foreach ( var_2 in self.useobject.visuals )
                var_2 hide();

            self.useobject maps\mp\gametypes\_gameobjects::allowuse( "any" );
        }
    }
    else if ( isdefined( self.useobject ) && isdefined( self.useobject.visuals ) )
    {
        foreach ( var_2 in self.useobject.visuals )
        {
            var_2 show();
            var_2 setmodel( "mil_semtex_belt" );
        }

        self.useobject maps\mp\gametypes\_gameobjects::allowuse( "none" );
    }
}

trap_onuse( var_0 )
{
    self.parent trap_set_can_use( 0 );
    self.parent notify( "trap_triggered" );
    self.parent.owner = var_0;
    self.parent thread trap_owner_watch();
    self.parent thread trap_active_watch();
}

trap_owner_watch()
{
    self endon( "trap_activated" );
    self.owner waittill( "death" );
    trap_set_can_use( 1 );
}

trap_active_watch()
{
    self endon( "trap_activated" );
    self.owner endon( "death" );

    for (;;)
    {
        self.activate_trigger waittill( "trigger", var_0 );

        if ( trap_can_player_trigger( var_0 ) )
            break;
    }

    self notify( "trap_activated" );
}

trap_can_player_trigger( var_0 )
{
    if ( !isdefined( self.owner ) )
        return 0;

    if ( isagent( var_0 ) && isdefined( var_0.owner ) && isdefined( self.owner ) && var_0.owner == self.owner )
        return 0;

    if ( !level.teambased )
        return var_0 != self.owner;

    if ( var_0.team != self.owner.team )
        return 1;

    return 0;
}

tree_bridges()
{
    precachempanim( "mp_prisonbreak_tree_fall" );
    var_0 = common_scripts\utility::getstructarray( "tree_bridge", "targetname" );
    common_scripts\utility::array_thread( var_0, ::tree_bridge_init );
}

tree_bridge_init()
{
    self.tree = undefined;
    self.clip_up = undefined;
    self.clip_down = undefined;
    self.clip_up_delete = undefined;
    self.linked_ents = [];
    var_0 = getentarray( self.target, "targetname" );
    var_1 = common_scripts\utility::getstructarray( self.target, "targetname" );
    var_0 = common_scripts\utility::array_combine( var_0, var_1 );

    foreach ( var_3 in var_0 )
    {
        if ( !isdefined( var_3.script_noteworthy ) )
            continue;

        switch ( var_3.script_noteworthy )
        {
            case "the_tree":
                self.tree = var_3;
                thread tree_bridge_damage_watch( var_3, 0 );
                break;
            case "clip_up_delete":
                self.clip_up_delete = var_3;
                break;
            case "clip_up":
                self.clip_up = var_3;
                self.linked_ents[self.linked_ents.size] = var_3;
                break;
            case "clip_down":
                self.clip_down = var_3;
                self.clip_down common_scripts\utility::trigger_off();
                break;
            case "link":
                self.linked_ents[self.linked_ents.size] = var_3;
                break;
            case "delete":
                self.decal = var_3;
                break;
            case "killcam":
                self.killcament = spawn( "script_model", var_3.origin );
                self.killcament setmodel( "tag_origin" );
                break;
            default:
                break;
        }
    }

    self.animated_prop = spawn( "script_model", self.tree.origin );
    self.animated_prop setmodel( "generic_prop_raven" );
    self.animated_prop.angles = self.tree.angles;
    self.tree linkto( self.animated_prop, "j_prop_2" );

    foreach ( var_6 in self.linked_ents )
        var_6 linkto( self.tree );

    thread tree_bridge_run();
}

tree_bridge_damage_watch( var_0, var_1 )
{
    self endon( "tree_down" );

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

    var_2 = 1000000;
    var_3 = 100;
    var_0.health = var_2;
    var_0 setcandamage( 1 );

    for (;;)
    {
        var_0 waittill( "damage", var_4, var_5, var_6, var_7, var_8 );
        var_5 thread maps\mp\gametypes\_damagefeedback::updatedamagefeedback( "tree" );

        if ( var_0.health < var_2 - var_3 )
            break;
    }

    var_0 setcandamage( 0 );

    if ( isdefined( self.tree ) )
        self.tree playsound( "scn_prison_tree_fall" );

    if ( var_1 )
        var_0 delete();

    self.attacker = var_5;
    self notify( "tree_down" );
}

#using_animtree("animated_props");

tree_bridge_run()
{
    self waittill( "tree_down" );

    if ( isdefined( self.decal ) )
        self.decal delete();

    if ( isdefined( self.clip_up_delete ) )
        self.clip_up_delete delete();

    self.clip_up connectpaths();
    self.tree maps\mp\_movers::notify_moving_platform_invalid();
    self.animated_prop scriptmodelplayanimdeltamotion( "mp_prisonbreak_tree_fall" );
    var_0 = getanimlength( %mp_prisonbreak_tree_fall );
    var_1 = var_0 - 0.3;
    var_2 = getent( "tree_impact_sound_origin", "targetname" );
    var_2 maps\mp\_utility::delaythread( var_1, ::playsound_wrapper, "scn_prison_tree_impact" );
    wait( var_1 );
    self.clip_down common_scripts\utility::trigger_on();
    self.clip_down dontinterpolate();
    self.clip_up maps\mp\_movers::notify_moving_platform_invalid();
    self.clip_up delete();

    foreach ( var_4 in level.characters )
    {
        if ( var_4 istouching( self.clip_down ) && isalive( var_4 ) )
        {
            if ( isdefined( self.attacker ) && isdefined( self.attacker.team ) && self.attacker.team == var_4.team )
            {
                var_4 maps\mp\_movers::mover_suicide();
                continue;
            }

            self.clip_down.killcament = self.killcament;
            var_4 dodamage( var_4.health + 500, var_4.origin, self.attacker, self.clip_down, "MOD_CRUSH" );
        }
    }

    foreach ( var_7 in level.remote_uav )
    {
        if ( var_7 istouching( self.clip_down ) )
            var_7 notify( "death" );
    }

    var_9 = getent( "tree_base_clip", "targetname" );

    if ( isdefined( var_9 ) )
        var_9 delete();
}

playsound_wrapper( var_0 )
{
    self playsound( var_0 );
}

log_piles()
{
    if ( getdvar( "r_reflectionProbeGenerate" ) == "1" )
        return;

    log_piles_precache();
    wait 0.05;
    var_0 = common_scripts\utility::getstructarray( "logpile", "targetname" );
    common_scripts\utility::array_thread( var_0, ::log_pile_init );
}

log_piles_precache()
{
    level.log_visual_link_joints = [];
    level.log_visual_link_joints["ten_log_roll"] = "j_log_5";
    level.log_anim_lengths = [];
    level.log_anim_lengths["ten_log_roll"] = getanimlength( %mp_prisonbreak_log_roll );
    level.log_anims = [];
    level.log_anims["ten_log_roll"] = "mp_prisonbreak_log_roll";

    foreach ( var_2, var_1 in level.log_anims )
        precachempanim( var_1 );
}

log_pile_init()
{
    self.logs = [];
    self.animated_logs = [];
    self.log_supports = [];
    self.log_supports_broken = [];
    self.clip_delete = [];
    self.clip_show = [];
    self.clip_move = [];
    self.kill_trigger = undefined;
    self.kill_trigger_linked = [];
    var_0 = undefined;
    var_1 = undefined;

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

    var_2 = getentarray( self.target, "targetname" );
    var_2 = common_scripts\utility::array_combine( var_2, common_scripts\utility::getstructarray( self.target, "targetname" ) );

    foreach ( var_4 in var_2 )
    {
        if ( !isdefined( var_4.script_noteworthy ) )
            continue;

        switch ( var_4.script_noteworthy )
        {
            case "log_with_use_visuals":
                var_0 = var_4;
            case "log":
                self.logs[self.logs.size] = var_4;

                if ( isdefined( var_4.target ) )
                    var_4.endpos = common_scripts\utility::getstruct( var_4.target, "targetname" );

                break;
            case "animated_log_use_visuals":
                var_0 = var_4;

                if ( isdefined( var_4.script_animation ) )
                    var_1 = level.log_visual_link_joints[var_4.script_animation];

                thread log_pile_support_damage_watch( var_4 );
            case "animated_log":
                if ( isdefined( var_4.script_animation ) && isdefined( level.log_anims[var_4.script_animation] ) )
                    self.animated_logs[self.animated_logs.size] = var_4;

                break;
            case "log_support":
                self.log_supports[self.log_supports.size] = var_4;
                thread log_pile_support_damage_watch( var_4 );
                break;
            case "log_support_broken":
                self.log_supports_broken[self.log_supports_broken.size] = var_4;
                var_4 hide();
                break;
            case "clip_delete":
                self.clip_delete[self.clip_delete.size] = var_4;
                break;
            case "clip_move":
                if ( isdefined( var_4.target ) )
                {
                    var_4.end_pos = common_scripts\utility::getstruct( var_4.target, "targetname" );

                    if ( isdefined( var_4.end_pos ) && isdefined( var_4.end_pos.target ) )
                    {
                        var_4.start_pos = common_scripts\utility::getstruct( var_4.end_pos.target, "targetname" );

                        if ( isdefined( var_4.start_pos ) )
                        {
                            var_4.move_delta = var_4.end_pos.origin - var_4.start_pos.origin;

                            if ( var_4 is_dynamic_path() )
                                var_4 connectpaths();

                            var_4.origin = var_4.origin - var_4.move_delta;
                            self.clip_move[self.clip_move.size] = var_4;
                        }
                    }
                }

                break;
            case "clip_show":
                self.clip_show[self.clip_show.size] = var_4;
                var_4 hide();
                var_4 notsolid();
                break;
            case "kill_trigger":
                self.kill_trigger = var_4;

                if ( isdefined( self.kill_trigger.target ) )
                {
                    self.kill_trigger.start_pos = common_scripts\utility::getstruct( self.kill_trigger.target, "targetname" );

                    if ( isdefined( self.kill_trigger.start_pos ) && isdefined( self.kill_trigger.start_pos.target ) )
                    {
                        self.kill_trigger.end_pos = common_scripts\utility::getstruct( self.kill_trigger.start_pos.target, "targetname" );

                        if ( isdefined( self.kill_trigger.end_pos ) )
                        {
                            self.kill_trigger.script_mover = spawn( "script_model", self.kill_trigger.start_pos.origin );
                            self.kill_trigger.script_mover setmodel( "tag_origin" );
                            self.kill_trigger enablelinkto();
                            self.kill_trigger linkto( self.kill_trigger.script_mover, "tag_origin" );
                        }
                    }
                }

                break;
            case "kill_trigger_link":
                self.kill_trigger_linked[self.kill_trigger_linked.size] = var_4;
                break;
            case "use_icon":
                self.use_icon_origin = var_4.origin;
                self.use_icon_angles = var_4.angles;
                break;
            case "killcam":
                self.killcament = spawn( "script_model", var_4.origin );
                self.killcament setmodel( "tag_origin" );
            default:
                break;
        }
    }

    if ( isdefined( self.kill_trigger ) && isdefined( self.kill_trigger.script_mover ) )
    {
        if ( isdefined( self.killcament ) )
            self.kill_trigger.script_mover.killcament = self.killcament;
        else
            self.kill_trigger.script_mover.killcament = self.kill_trigger.script_mover;
    }

    if ( isdefined( var_0 ) )
    {
        foreach ( var_7 in self.kill_trigger_linked )
        {
            var_7.killcament = self.killcament;
            var_7 enablelinkto();
            var_7.no_moving_platfrom_unlink = 1;
            var_7 linkto( var_0, var_7.script_parameters );
        }
    }

    self.nodes = getnodearray( self.target, "targetname" );

    foreach ( var_10 in self.nodes )
        var_10 disconnectnode();

    if ( ( self.logs.size || self.animated_logs.size ) && self.log_supports.size > 0 )
    {
        thread log_pile_run();
        thread trap_init();
    }

    if ( isdefined( var_0 ) && isdefined( self.use_model ) )
    {
        if ( isdefined( var_1 ) )
            self.use_model linkto( var_0, var_1 );
        else
            self.use_model linkto( var_0 );
    }
}

log_pile_support_damage_watch( var_0 )
{
    self endon( "trap_activated" );
    var_1 = 1000000;
    var_0.health = var_1;
    var_0 setcandamage( 1 );

    for (;;)
    {
        var_0 waittill( "damage", var_2, var_3, var_4, var_5, var_6 );
        var_0.health = var_1;

        if ( is_explosive( var_6 ) && var_2 >= 10 )
        {
            self.owner = var_3;
            break;
        }
    }

    var_0 setcandamage( 0 );
    self notify( "trap_activated" );
}

log_pile_run()
{
    self waittill( "trap_activated" );
    trap_set_can_use( 0 );
    var_0 = 2.3;
    thread log_pile_kill_trigger( self.kill_trigger );

    foreach ( var_2 in self.kill_trigger_linked )
        thread log_pile_kill_trigger( var_2 );

    thread log_pile_kill_trigger_end( var_0 );
    common_scripts\utility::array_thread( self.log_supports, maps\mp\_movers::notify_moving_platform_invalid );
    common_scripts\utility::array_call( self.log_supports, ::delete );
    common_scripts\utility::array_call( self.log_supports_broken, ::show );
    common_scripts\utility::array_thread( self.clip_delete, maps\mp\_movers::notify_moving_platform_invalid );
    common_scripts\utility::array_call( self.clip_delete, ::delete );
    common_scripts\utility::array_call( self.clip_show, ::show );
    common_scripts\utility::array_call( self.clip_show, ::solid );

    foreach ( var_5 in self.clip_move )
    {
        if ( var_5 is_dynamic_path() )
            var_5 common_scripts\utility::delaycall( var_0, ::disconnectpaths );

        var_5 thread log_pile_clip_move( 1.5, 0.5 );
    }

    if ( isdefined( self.kill_trigger ) && isdefined( self.kill_trigger.script_mover ) )
        self.kill_trigger.script_mover moveto( self.kill_trigger.end_pos.origin, var_0, var_0 * 0.5, 0 );

    foreach ( var_8 in self.logs )
    {
        if ( isdefined( var_8.endpos ) )
        {
            var_8 moveto( var_8.endpos.origin, var_0, var_0 * 0.5, 0 );
            var_9 = var_8.endpos.angles - var_8.angles;
            var_9 = normalize_angles_180( var_9 );
            var_9 = var_9 + ( 1440, 0, 0 );
            var_10 = var_9 / var_0;
            var_8 rotatevelocity( var_10, var_0, var_0 * 0.5, 0 );
        }
    }

    foreach ( var_13 in self.animated_logs )
    {
        var_13 maps\mp\_movers::notify_moving_platform_invalid();
        var_13 scriptmodelplayanimdeltamotion( level.log_anims[var_13.script_animation] );
        var_14 = ( -20000, 0, 9000 );
        var_15 = ( 0, 0, 50 );
        var_16 = getent( "care_package_delete_volume", "targetname" );
        maps\mp\killstreaks\_airdrop::throw_linked_care_packages( var_13, var_15, var_14, var_16 );
        var_17 = level.log_anim_lengths[var_13.script_animation];

        if ( isdefined( var_17 ) && var_17 > var_0 )
            var_0 = var_17;
    }

    if ( isdefined( self.animated_logs ) && self.animated_logs.size > 0 )
        self.animated_logs[0] playsoundonmovingent( "scn_prison_logtrap_logs_roll" );

    wait( var_0 );
    self notify( "log_roll_done" );
    wait 0.05;

    foreach ( var_20 in self.nodes )
        var_20 connectnode();
}

log_pile_clip_move( var_0, var_1 )
{
    wait( var_0 );
    self moveto( self.origin + self.move_delta, var_1 );
}

log_pile_kill_trigger( var_0 )
{
    if ( !isdefined( var_0 ) )
        return;

    self endon( "log_roll_end_kill_trigger" );

    for (;;)
    {
        var_0 waittill( "trigger", var_1 );

        if ( !log_pile_can_damage_player( var_1 ) )
            continue;

        var_2 = var_0;

        if ( isdefined( var_0.script_mover ) )
            var_2 = var_0.script_mover;

        var_3 = self.owner;

        if ( isagent( var_1 ) && isdefined( var_1.owner ) && isdefined( var_3 ) && var_1.owner == var_3 )
        {
            var_1 maps\mp\_movers::mover_suicide();
            continue;
        }

        var_2.killcament = self.killcament;
        var_2 radiusdamage( var_1.origin, 8, 1000, 1000, var_3, "MOD_CRUSH", "none" );
    }
}

log_pile_kill_trigger_end( var_0 )
{
    wait( var_0 );
    self notify( "log_roll_end_kill_trigger" );
}

log_pile_can_damage_player( var_0 )
{
    return 1;
}

falling_rocks()
{
    var_0 = getentarray( "falling_rock", "targetname" );
    common_scripts\utility::array_thread( var_0, ::falling_rock_init );
}

falling_rock_init()
{
    self.fall_to = [];
    self.clip_move = [];
    var_0 = getentarray( self.target, "targetname" );
    var_1 = common_scripts\utility::getstructarray( self.target, "targetname" );
    var_0 = common_scripts\utility::array_combine( var_0, var_1 );

    foreach ( var_3 in var_0 )
    {
        if ( !isdefined( var_3.script_noteworthy ) )
            continue;

        switch ( var_3.script_noteworthy )
        {
            case "kill_trigger":
                var_3 enablelinkto();
                var_3 linkto( self );
                self.kill_trigger = var_3;
                break;
            case "rock_clip":
                var_3 linkto( self );
                self.clip = var_3;
                break;
            case "fall_to":
                self.fall_to[self.fall_to.size] = var_3;
                var_3.fall_dist = distance( self.origin, var_3.origin );

                for ( self.fall_dist = var_3.fall_dist; isdefined( var_3.target ); self.fall_dist = self.fall_dist + var_3.fall_dist )
                {
                    var_4 = var_3;
                    var_3 = common_scripts\utility::getstruct( var_3.target, "targetname" );

                    if ( !isdefined( var_3 ) )
                        break;

                    self.fall_to[self.fall_to.size] = var_3;
                    var_3.fall_dist = distance( var_4.origin, var_3.origin );
                }

                break;
            case "clip_move":
                if ( isdefined( var_3.target ) )
                {
                    var_3.end_pos = common_scripts\utility::getstruct( var_3.target, "targetname" );

                    if ( isdefined( var_3.end_pos ) && isdefined( var_3.end_pos.target ) )
                    {
                        var_3.start_pos = common_scripts\utility::getstruct( var_3.end_pos.target, "targetname" );

                        if ( isdefined( var_3.start_pos ) )
                        {
                            var_3.move_delta = var_3.end_pos.origin - var_3.start_pos.origin;
                            var_3.origin = var_3.origin - var_3.move_delta;

                            if ( var_3 is_dynamic_path() )
                                var_3 connectpaths();

                            self.clip_move[self.clip_move.size] = var_3;
                        }
                    }
                }

                break;
            default:
                break;
        }
    }

    thread falling_rock_damage_watch();
    thread falling_rock_run();
}

is_dynamic_path()
{
    return isdefined( self.spawnflags ) && self.spawnflags & 1;
}

falling_rock_damage_watch()
{
    var_0 = 1000000;
    self.health = var_0;
    self setcandamage( 1 );

    for (;;)
    {
        self waittill( "damage", var_1, var_2, var_3, var_4, var_5 );
        self.health = var_0;

        if ( is_explosive( var_5 ) )
        {
            self.attacker = var_2;
            break;
        }
    }

    self setcandamage( 0 );
    self notify( "rock_fall" );
}

falling_rock_run()
{
    self waittill( "rock_fall" );
    var_0 = 1.0;
    thread falling_rock_kill_trigger();
    var_1 = 1;

    for ( var_2 = 0; var_2 < self.fall_to.size; var_2++ )
    {
        var_3 = self.fall_to[var_2];
        var_4 = var_3.fall_dist / self.fall_dist * var_0;
        self moveto( var_3.origin, var_4, var_4 * var_1, 0 );
        self rotateto( var_3.angles, var_4, var_4 * var_1, 0 );

        if ( var_2 == self.fall_to.size - 1 )
        {
            foreach ( var_6 in self.clip_move )
            {
                if ( var_6 is_dynamic_path() )
                    var_6 common_scripts\utility::delaycall( var_4, ::disconnectpaths );

                var_6 moveto( var_6.origin + var_6.move_delta, var_4 );
            }
        }

        self waittill( "movedone" );
        var_1 = 0;
    }

    self notify( "rock_move_done" );
    self.clip delete();
    self.kill_trigger delete();
}

falling_rock_kill_trigger()
{
    self endon( "death" );
    self endon( "rock_move_done" );

    for (;;)
    {
        self.kill_trigger waittill( "trigger", var_0 );
        radiusdamage( var_0.origin, 8, 1000, 1000, self.attacker, "MOD_CRUSH" );
    }
}

rock_slides()
{
    rock_slides_precache();
    wait 0.05;
    var_0 = common_scripts\utility::getstructarray( "rock_slide", "targetname" );
    common_scripts\utility::array_thread( var_0, ::rock_slides_init );
}

rock_slides_precache()
{

}

rock_slides_init()
{
    self.ground_ents = [];
    self.rocks = [];
    var_0 = getentarray( self.target, "targetname" );
    var_1 = 1;

    foreach ( var_3 in var_0 )
    {
        if ( !isdefined( var_3.script_noteworthy ) )
            continue;

        switch ( var_3.script_noteworthy )
        {
            case "ground":
                if ( isdefined( var_3.target ) && !var_1 )
                {
                    var_3.start_pos = common_scripts\utility::getstruct( var_3.target, "targetname" );

                    if ( isdefined( var_3.start_pos ) && isdefined( var_3.start_pos.target ) )
                    {
                        var_3.end_pos = common_scripts\utility::getstruct( var_3.start_pos.target, "targetname" );

                        if ( isdefined( var_3.end_pos ) )
                        {
                            var_3.move_ent = spawn( "script_model", var_3.start_pos.origin );
                            var_3.move_ent setmodel( "tag_origin" );
                            var_3.move_ent.angles = var_3.start_pos.angles;
                            var_3 linkto( var_3.move_ent );
                            self.ground_ents[self.ground_ents.size] = var_3;
                            var_3.move_delete = isdefined( var_3.end_pos.script_noteworthy ) && var_3.end_pos.script_noteworthy == "delete";
                        }
                    }
                }

                break;
            case "rock":
                if ( var_1 )
                    var_3 delete();
                else
                {
                    var_3.end_pos = common_scripts\utility::getstruct( var_3.target, "targetname" );

                    if ( isdefined( var_3.end_pos ) )
                    {
                        self.rocks[self.rocks.size] = var_3;
                        var_3.move_delete = isdefined( var_3.end_pos.script_noteworthy ) && var_3.end_pos.script_noteworthy == "delete";
                    }
                }

                break;
            default:
                break;
        }
    }

    if ( !var_1 )
    {
        common_scripts\utility::array_thread( self.ground_ents, ::rock_slide_damage_watch, self );
        thread rock_slide_run();
    }

    thread trap_init( var_1 );
}

rock_slide_damage_watch( var_0 )
{
    var_0 endon( "trap_activated" );
    var_1 = 1000000;
    self.health = var_1;
    self setcandamage( 1 );

    for (;;)
    {
        self waittill( "damage", var_2, var_3, var_4, var_5, var_6 );
        self.health = var_1;

        if ( is_explosive( var_6 ) )
        {
            self.attacker = var_3;
            break;
        }
    }

    self setcandamage( 0 );
    var_0 notify( "trap_activated" );
}

rock_slide_run()
{
    self waittill( "trap_activated" );
    earthquake( 0.4, 3, self.origin, 800 );
    var_0 = 1.5;

    foreach ( var_2 in self.rocks )
    {
        var_2 moveto( var_2.end_pos.origin, var_0, var_0, 0 );
        var_2 rotateto( var_2.end_pos.angles, var_0, var_0, 0 );

        if ( var_2.move_delete )
            var_2 common_scripts\utility::delaycall( var_0, ::delete );
    }

    wait 0.5;
    var_4 = 1;

    foreach ( var_6 in self.ground_ents )
    {
        var_6.move_ent moveto( var_6.end_pos.origin, var_4, var_4, 0 );
        var_6.move_ent rotateto( var_6.end_pos.angles, var_4, var_4, 0 );

        if ( var_6.move_delete )
            var_6 common_scripts\utility::delaycall( var_0, ::delete );
    }
}

hand_icon( var_0, var_1, var_2, var_3 )
{
    if ( level.createfx_enabled )
        return;

    if ( !isdefined( level.hand_icon_count ) )
        level.hand_icon_count = 0;

    level.hand_icon_count++;
    var_4 = "hand_icon_" + level.hand_icon_count;
    hand_icon_update( var_0, var_1, var_2, var_4, var_3 );

    foreach ( var_6 in level.players )
    {
        if ( isdefined( var_6.hand_icons ) && isdefined( var_6.hand_icons[var_4] ) )
            var_6.hand_icons[var_4] thread hand_icon_fade_out();
    }
}

hand_icon_update( var_0, var_1, var_2, var_3, var_4 )
{
    if ( isdefined( var_4 ) )
    {
        if ( isstring( var_4 ) )
            var_4 = [ var_4 ];

        foreach ( var_6 in var_4 )
            self endon( var_6 );
    }

    while ( !isdefined( level.players ) )
        wait 0.05;

    var_8 = 200;
    var_9 = "hint_usable";
    var_10 = 0;

    switch ( var_0 )
    {
        default:
            break;
    }

    var_11 = undefined;

    if ( isdefined( var_2 ) )
        var_11 = anglestoforward( var_2 );

    var_12 = var_8 * var_8;

    for (;;)
    {
        foreach ( var_14 in level.players )
        {
            if ( !isdefined( var_14.hand_icons ) )
                var_14.hand_icons = [];

            var_15 = var_14.origin + ( 0, 0, 50 );
            var_16 = distancesquared( var_15, var_1 );
            var_17 = 1;

            if ( isdefined( var_11 ) )
            {
                var_18 = vectornormalize( var_15 - var_1 );
                var_17 = vectordot( var_11, var_18 ) > 0.2;
            }

            if ( var_16 <= var_12 && var_17 && ( !isdefined( self.in_use ) || !self.in_use ) && !var_14 maps\mp\_utility::isusingremote() )
            {
                if ( !isdefined( var_14.hand_icons[var_3] ) )
                {
                    var_14.hand_icons[var_3] = hand_icon_create( var_14, var_9, var_1, var_10 );
                    var_14.hand_icons[var_3].alpha = 0;
                }

                var_14.hand_icons[var_3] notify( "stop_fade" );
                var_14.hand_icons[var_3] thread hand_icon_fade_in();
                continue;
            }

            if ( isdefined( var_14.hand_icons[var_3] ) )
                var_14.hand_icons[var_3] thread hand_icon_fade_out();
        }

        wait 0.05;
    }
}

hand_icon_create( var_0, var_1, var_2, var_3 )
{
    var_1 = var_0 maps\mp\gametypes\_hud_util::createicon( var_1, 16, 16 );
    var_1 setwaypoint( 1, var_3 );
    var_1.x = var_2[0];
    var_1.y = var_2[1];
    var_1.z = var_2[2];
    return var_1;
}

hand_icon_fade_in()
{
    self endon( "death" );

    if ( self.alpha == 1 )
        return;

    self fadeovertime( 0.5 );
    self.alpha = 1;
}

hand_icon_fade_out()
{
    self endon( "death" );
    self endon( "stop_fade" );

    if ( self.alpha == 0 )
        return;

    var_0 = 0.5;
    self fadeovertime( var_0 );
    self.alpha = 0;
    wait( var_0 );
    self destroy();
}

tower_radio()
{
    var_0 = getent( "tower_radio", "targetname" );
    var_0.tracklist = [];
    var_0.tracklist[0] = "mus_emt_portable_radio_01";
    var_0.tracklist[1] = "mus_emt_portable_radio_02";
    var_0.tracklist[2] = "mus_emt_portable_radio_03";
    maps\mp\_utility::gameflagwait( "prematch_done" );
    var_0 thread tower_radio_damage_watch();
    var_0 endon( "death" );

    for (;;)
    {
        level waittill( "connected", var_1 );
        var_0 thread tower_radio_sounds( var_1 );
    }
}

tower_radio_damage_watch()
{
    self.health = 10000;
    self setcandamage( 1 );
    self waittill( "damage", var_0, var_1, var_2, var_3, var_4 );
    self playsound( "radio_destroyed_static" );
    self physicslaunchclient( var_3, var_2 );
}

tower_radio_sounds( var_0 )
{
    self endon( "damage" );
    var_0 endon( "death" );
    var_0 endon( "disconnect" );
    var_0 waittill( "spawned_player" );
    common_scripts\utility::waitframe();
    var_1 = "";

    for (;;)
    {
        for ( var_2 = var_1; var_2 == var_1; var_2 = common_scripts\utility::random( self.tracklist ) )
        {

        }

        var_3 = lookupsoundlength( var_2 ) / 1000;

        if ( var_3 < 0.1 )
            wait 5.0;
        else
            self playsoundtoplayer( var_2, var_0 );

        wait( var_3 );
        var_1 = var_2;
    }
}
