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

main()
{
    maps\mp\mp_fahrenheit_precache::main();
    maps\createart\mp_fahrenheit_art::main();
    maps\mp\mp_fahrenheit_fx::main();
    precache();
    maps\mp\_load::main();
    common_scripts\utility::flag_init( "stop_dynamic_events" );
    level.rainscriptables = [];
    level.rainscriptables = getscriptablearray( "rain_scriptable", "targetname" );
    level.round_start_fraction = 0;
    level.round_end_fraction = 1;
    level.storm_stage = 0;
    level.stage_1_fraction = 0.4;
    level.stage_2_fraction = 0.7;
    var_0 = maps\mp\_utility::gettimelimit() * 60;

    if ( var_0 <= 0 )
        var_0 = 600;

    level.assumed_match_length = var_0;
    maps\mp\_compass::setupminimap( "compass_map_mp_fahrenheit" );
    setdvar( "r_reactiveMotionWindAmplitudeScale", 0.5 );
    setdvar( "r_reactiveMotionWindFrequencyScale", 0.5 );

    if ( level.ps3 || level.xenon )
        setdvar( "sm_sunShadowScale", "0.8" );

    maps\mp\_utility::setdvar_cg_ng( "r_specularColorScale", 3, 9 );
    maps\mp\_utility::setdvar_cg_ng( "r_diffuseColorScale", 1.6, 2.2 );
    setdvar( "r_ssaorejectdepth", 1500 );
    setdvar( "r_ssaofadedepth", 1200 );
    setdvar( "r_sky_fog_intensity", "1" );
    setdvar( "r_sky_fog_min_angle", "56.6766" );
    setdvar( "r_sky_fog_max_angle", "75" );
    setdvar( "r_lightGridEnableTweaks", 1 );
    setdvar( "r_lightGridIntensity", 1.33 );
    game["attackers"] = "allies";
    game["defenders"] = "axis";
    common_scripts\utility::flag_init( "begin_storm" );
    level thread plant_anims();
    common_scripts\utility::waitframe();

    if ( maps\mp\_utility::isroundbased() )
        compute_round_based_percentages( var_0 );

    level thread sky_and_visionsets( level.assumed_match_length, level.round_start_fraction, level.round_end_fraction );
    level thread connect_watch();
    thread setupelevator();
    level thread initextracollision();
}

initextracollision()
{
    var_0 = getent( "clip128x128x8", "targetname" );
    var_1 = spawn( "script_model", ( -2352, -1938, 512 ) );
    var_1.angles = ( 0, 0, 0 );
    var_1 clonebrushmodeltoscriptmodel( var_0 );
    var_2 = getent( "clip32x32x256", "targetname" );
    var_3 = spawn( "script_model", ( 176, -2420, 848 ) );
    var_3.angles = ( 0, 0, 0 );
    var_3 clonebrushmodeltoscriptmodel( var_2 );
    var_4 = getent( "clip32x32x256", "targetname" );
    var_5 = spawn( "script_model", ( 176, -2452, 848 ) );
    var_5.angles = ( 0, 0, 0 );
    var_5 clonebrushmodeltoscriptmodel( var_4 );
    var_6 = getent( "clip32x32x256", "targetname" );
    var_7 = spawn( "script_model", ( 666, -1824, 868 ) );
    var_7.angles = ( 0, 0, 0 );
    var_7 clonebrushmodeltoscriptmodel( var_6 );
    var_8 = getent( "clip256x256x8", "targetname" );
    var_9 = spawn( "script_model", ( -1372, -3232, 784 ) );
    var_9.angles = ( 0, 0, 0 );
    var_9 clonebrushmodeltoscriptmodel( var_8 );
    var_10 = getent( "clip64x64x256", "targetname" );
    var_11 = spawn( "script_model", ( -1928, 624, 680 ) );
    var_11.angles = ( 0, 0, -90 );
    var_11 clonebrushmodeltoscriptmodel( var_10 );
    var_12 = getent( "clip256x256x8", "targetname" );
    var_13 = spawn( "script_model", ( -1808, 760, 648 ) );
    var_13.angles = ( 0, 0, 0 );
    var_13 clonebrushmodeltoscriptmodel( var_12 );
    var_14 = spawn( "trigger_radius", ( -1216, 80, 496 ), 0, 864, 110 );
    var_14.radius = 864;
    var_14.height = 110;
    var_14.angles = ( 0, 0, 0 );
    var_14.targetname = "gryphonDeath";
    var_15 = spawn( "trigger_radius", ( 576, -3104, 312 ), 0, 2240, 75 );
    var_15.radius = 2240;
    var_15.height = 75;
    var_15.angles = ( 0, 0, 0 );
    var_15.targetname = "gryphonDeath";
    var_16 = spawn( "trigger_radius", ( -1080, -4136, 520 ), 0, 176, 528 );
    var_16.radius = 176;
    var_16.height = 528;
    var_16.angles = ( 0, 0, 0 );
    var_16.targetname = "gryphonDeath";
    var_17 = spawn( "trigger_radius", ( -1184, -3808, 416 ), 0, 176, 96 );
    var_17.radius = 176;
    var_17.height = 96;
    var_17.angles = ( 0, 0, 0 );
    var_17.targetname = "gryphonDeath";
    var_18 = spawn( "trigger_radius", ( 448, -2144, 896 ), 0, 400, 128 );
    var_18.radius = 400;
    var_18.height = 128;
    var_18.angles = ( 0, 0, 0 );
    var_18.targetname = "antiFoliage";
    level thread watchantifoliage( var_18 );
    level thread maps\mp\_utility::killtrigger( ( -194, 198, 352 ), 700, 256 );
    level thread maps\mp\_utility::killtrigger( ( -2148, -340, 718 ), 96, 6 );
}

watchantifoliage( var_0 )
{
    level endon( "game_ended" );

    for (;;)
    {
        foreach ( var_2 in level.players )
        {
            wait 0.05;

            if ( !isdefined( var_2 ) )
                continue;

            if ( var_2 istouching( var_0 ) )
            {
                if ( isdefined( var_2.wasinantifoliage ) && var_2.wasinantifoliage )
                    continue;

                var_2 setignorefoliagesightingme( 1 );
                var_2.wasinantifoliage = 1;
                continue;
            }

            if ( isdefined( var_2.wasinantifoliage ) && var_2.wasinantifoliage )
            {
                var_2 setignorefoliagesightingme( 0 );
                var_2.wasinantifoliage = 0;
            }
        }

        wait 0.1;
    }
}

precache()
{

}

setupelevator()
{
    if ( level.gametype == "horde" )
        return;

    var_0 = spawnstruct();
    var_0.name = "elevator";
    var_0.doors = [];
    var_0.doors["floor1"] = [ "e_door_floor1_", "e_door_elevator_1_" ];
    var_0.doors["floor2"] = [ "e_door_floor2_", "e_door_elevator_2_" ];
    var_0.doors["elevator"] = [ "e_door_elevator_1_", "e_door_elevator_2_" ];
    var_0.doormovedist = 35;
    var_0.buttons = "elevator_button";
    var_0.trigblockname = "elevator_door_checker";
    maps\mp\_elevator::init_elevator( var_0 );
}

compute_round_based_percentages( var_0 )
{
    var_1 = maps\mp\_utility::getwatcheddvar( "roundlimit" );
    var_2 = maps\mp\_utility::getwatcheddvar( "winlimit" );

    if ( var_2 > 0 )
    {
        level.assumed_match_length = var_2 * var_0;

        if ( maps\mp\_utility::isfirstround() )
            var_3 = 0;
        else
            var_3 = max( game["roundsWon"]["allies"], game["roundsWon"]["axis"] );

        level.round_start_fraction = var_3 / var_2;
        level.round_end_fraction = ( var_3 + 1 ) / var_2;
    }
    else if ( var_1 > 0 )
    {
        level.assumed_match_length = var_1 * var_0;
        level.round_start_fraction = game["roundsPlayed"] / var_1;
        level.round_end_fraction = ( game["roundsPlayed"] + 1 ) / var_1;
    }
}

plant_anims()
{
    level.plants = getscriptablearray( "storm_plant", "targetname" );
    level waittill( "storm_stage_1" );
    plant_set_stage_directional( "stage_1", 180, 6, 1 );
}

plant_set_stage_directional( var_0, var_1, var_2, var_3 )
{
    var_4 = anglestoforward( ( 0, var_1, 0 ) );
    var_5 = anglestoright( ( 0, var_1, 0 ) );
    var_6 = undefined;
    var_7 = undefined;

    foreach ( var_9 in level.plants )
    {
        var_10 = disttoline( var_9.origin, ( 0, 0, 0 ), var_5 );

        if ( lrtest( var_9.origin, ( 0, 0, 0 ), var_5 ) == 2 )
            var_10 = var_10 * -1;

        if ( !isdefined( var_6 ) || var_10 < var_6 )
            var_6 = var_10;

        if ( !isdefined( var_7 ) || var_10 > var_7 )
            var_7 = var_10;

        var_9.temp_dist = var_10;
    }

    foreach ( var_9 in level.plants )
    {
        var_13 = ( var_9.temp_dist - var_6 ) / ( var_7 - var_6 );
        var_14 = var_2 * var_13;

        if ( isdefined( var_3 ) && var_3 > 0 )
            var_14 = var_14 + randomfloatrange( 0, var_3 );

        level thread plant_set_stage( var_9, var_0, var_14 );
    }
}

plant_set_stage( var_0, var_1, var_2 )
{
    if ( isdefined( var_2 ) && var_2 > 0 )
        wait( var_2 );

    var_0 setscriptablepartstate( "storm_plant", var_1 );
}

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

    if ( var_0 > 2 )
        var_0 = 0;

    if ( isdefined( level.rainscriptables ) )
    {
        foreach ( var_2 in level.rainscriptables )
            var_2 setscriptablepartstate( 0, var_0 );
    }
}

visiontest()
{
    wait 20;
    var_0 = 0;
    var_1 = 2;
    var_2 = -1;
    level.skydome = getent( "skydome", "targetname" );
    var_0 = var_0 + 1;

    if ( var_0 >= var_1 )
        var_0 = 0;

    iprintlnbold( "CHANGING VISIONSETS to:" + var_0 );

    foreach ( var_4 in level.players )
        var_4 visionsetstage( int( min( 1, var_0 ) ), 3 );

    level.skydome rotatepitch( var_2 * 45, 3 );
    var_2 = var_2 * -1;
    rainfxstage( 1 );
    wait 6;
}

fx_test()
{
    var_0 = [];
    var_0 = getscriptablearray( "rain_scriptable", "targetname" );

    for (;;)
    {
        var_0[0] setscriptablepartstate( 0, 0 );
        wait 5;
        var_0[0] setscriptablepartstate( 0, 1 );
        wait 5;
        var_0[0] setscriptablepartstate( 0, 2 );
        wait 5;
        var_0[0] setscriptablepartstate( 0, 3 );
        wait 5;
    }
}

sky_and_visionsets( var_0, var_1, var_2 )
{
    level.volmods = [];

    if ( common_scripts\utility::flag( "stop_dynamic_events" ) )
        return;

    level endon( "stop_dynamic_events" );
    var_3 = 0;
    var_4 = 10;
    maps\mp\_utility::gameflagwait( "prematch_done" );
    level.storm_stage = 0;
    var_5 = var_1;

    if ( var_1 < level.stage_1_fraction )
    {
        foreach ( var_7 in level.players )
            var_7 visionsetstage( int( min( 1, level.storm_stage ) ), 0.1 );

        var_9 = level.stage_1_fraction * var_0 - var_5 * var_0;
        wait( var_9 );
        var_5 = level.stage_1_fraction;
    }

    if ( var_1 < level.stage_2_fraction )
    {
        level notify( "storm_stage_1" );
        level.storm_stage = 1;
        common_scripts\utility::exploder( 1 );
        level thread storm_sound_stage( "storm_sound_stage_1" );
        level.rainemitent = spawn( "script_origin", ( 0, 0, 0 ) );
        storm_sounds_volmod( "scripted2", 0, 0 );
        wait 0.05;
        level.rainemitent playloopsound( "amb_fah_rain_light_loop" );
        storm_sounds_volmod( "scripted2", 1, 3 );
        var_10 = getscriptablearray( "sun_scriptable", "targetname" );

        foreach ( var_12 in var_10 )
            var_12 setscriptablepartstate( 0, "storm_stage_1" );

        foreach ( var_7 in level.players )
            var_7 visionsetstage( int( min( 1, level.storm_stage ) ), var_4 );

        wait( var_4 );
        rainfxstage( level.storm_stage );
        var_9 = level.stage_2_fraction * var_0 - ( var_5 * var_0 + var_4 );
        wait( var_9 );
        var_5 = level.stage_2_fraction;
    }

    level notify( "storm_stage_2" );
    level.storm_stage = 2;
    common_scripts\utility::exploder( 1 );
    level thread storm_sound_stage( "storm_sound_stage_2" );
    level.heavyrainemitent = spawn( "script_origin", ( 0, 0, 0 ) );
    storm_sounds_volmod( "scripted3", 0, 0 );
    wait 0.05;
    level.heavyrainemitent playloopsound( "amb_fah_rain_heavy_loop" );
    storm_sounds_volmod( "scripted3", 1, 3 );
    wait 0.05;
    storm_sounds_volmod( "scripted2", 0, 3 );
    rainfxstage( level.storm_stage );

    if ( var_1 >= level.stage_2_fraction )
    {
        foreach ( var_7 in level.players )
            var_7 visionsetstage( int( min( 1, level.storm_stage ) ), 0.1 );
    }
    else
    {
        foreach ( var_7 in level.players )
            var_7 visionsetstage( int( min( 1, level.storm_stage ) ), var_4 );
    }
}

storm_sound_stage( var_0 )
{
    var_1 = 0.9;
    var_2 = getentarray( var_0, "targetname" );

    foreach ( var_4 in var_2 )
    {
        var_5 = var_4.script_noteworthy;

        if ( isdefined( var_5 ) )
            var_4 playloopsound( var_5 );
        else
        {

        }

        wait( var_1 );
    }
}

storm_sounds_volmod( var_0, var_1, var_2 )
{
    level.volmods[var_0] = var_1;

    foreach ( var_4 in level.players )
        var_4 setvolmod( var_0, var_1, var_2 );
}

rotate_skydome( var_0, var_1, var_2 )
{
    var_3 = 0;
    var_4 = -70;
    var_0 = min( 1, var_0 / level.stage_1_fraction );
    var_1 = min( 1, var_1 / level.stage_1_fraction );
    level.skydome rotatepitch( 180, 0.1 );
    wait 0.1;
    level.skydome rotatepitch( var_0 * var_4, 0.1 );
    maps\mp\_utility::gameflagwait( "prematch_done" );
    level.skydome rotatepitch( ( var_1 - var_0 ) * var_4, max( 0.1, ( var_1 - var_0 ) * var_2 ) );
}

connect_watch()
{
    for (;;)
    {
        level waittill( "connected", var_0 );

        if ( isdefined( level.storm_stage ) )
            var_0 visionsetstage( int( min( 1, level.storm_stage ) ), 0.1 );

        foreach ( var_3, var_2 in level.volmods )
            var_0 setvolmod( var_3, var_2 );
    }
}

areaparallelpipid( var_0, var_1, var_2 )
{
    return var_0[0] * var_1[1] - var_0[1] * var_1[0] + ( var_1[0] * var_2[1] - var_2[0] * var_1[1] ) + ( var_2[0] * var_0[1] - var_0[0] * var_2[1] );
}

areatriange( var_0, var_1, var_2 )
{
    return areaparallelpipid( var_0, var_1, var_2 ) * 0.5;
}

lrtest( var_0, var_1, var_2, var_3 )
{
    if ( !isdefined( var_3 ) )
        var_3 = 0.0;

    var_4 = areaparallelpipid( var_1, var_2, var_0 );

    if ( var_4 > var_3 )
        return 1;

    if ( var_4 < var_3 * -1 )
        return 2;

    return 3;
}

project( var_0, var_1 )
{
    var_2 = vectordot( var_0, var_1 ) / lengthsquared( var_1 );
    return [ var_1 * var_2, var_2 ];
}

projecttoline( var_0, var_1, var_2 )
{
    var_0 = var_0 - var_1;
    [var_0, var_4] = project( var_0, var_2 - var_1 );
    var_0 = var_0 + var_1;
    return [ var_0, var_4 ];
}

projecttolineseg( var_0, var_1, var_2 )
{
    [var_0, var_4] = projecttoline( var_0, var_1, var_2 );

    if ( var_4 < 0.0 )
        var_0 = var_1;
    else if ( var_4 > 1.0 )
        var_0 = var_2;

    return [ var_0, var_4 ];
}

disttoline( var_0, var_1, var_2 )
{
    [var_4, var_5] = projecttoline( var_0, var_1, var_2 );
    return distance( var_4, var_0 );
}
