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

init()
{
    level.killstreakfuncs["mrsiartillery"] = ::tryusestrike;
    var_0 = spawnstruct();
    var_0.weaponname = "airdrop_marker_mp";
    var_0.projectilename = "mrsiartillery_projectile_mp";
    var_0.numstrikes = 6;
    var_0.initialdelay = 1.0;
    var_0.minfiredelay = 0.375;
    var_0.maxfiredelay = 0.5;
    var_0.strikeradius = 150;

    if ( !isdefined( level.killstreakconfigdata ) )
        level.killstreakconfigdata = [];

    level.killstreakconfigdata["mrsiartillery"] = var_0;
}

tryusestrike( var_0, var_1 )
{
    var_2 = level.killstreakconfigdata["mrsiartillery"];
    var_3 = maps\mp\killstreaks\_designator_grenade::designator_start( "mrsiartillery", var_2.weaponname, ::ontargetacquired );

    if ( !isdefined( var_3 ) || !var_3 )
        return 0;
    else
        return 1;
}

ontargetacquired( var_0, var_1 )
{
    var_2 = level.killstreakconfigdata[var_0];
    var_3 = var_1.owner;
    var_4 = var_1.origin;
    var_1 detonate();
    dostrike( var_3, var_0, var_3.origin, var_4 );
}

dostrike( var_0, var_1, var_2, var_3 )
{
    var_4 = level.killstreakconfigdata[var_1];
    var_5 = var_3 - var_2;
    var_6 = ( var_5[0], var_5[1], 0 );
    var_5 = vectornormalize( var_5 );
    var_7 = var_3;
    var_8 = maps\mp\killstreaks\_killstreaks::findunobstructedfiringpoint( var_0, var_3 + ( 0, 0, 10 ), 10000 );

    if ( isdefined( var_8 ) )
    {
        iprintln( "Firing Motar!" );
        wait( var_4.initialdelay );
        wait( randomfloatrange( var_4.minfiredelay, var_4.maxfiredelay ) );
        var_9 = magicbullet( var_4.projectilename, var_8, var_7, var_0 );

        for ( var_10 = 1; var_10 < var_4.numstrikes; var_10++ )
        {
            wait( randomfloatrange( var_4.minfiredelay, var_4.maxfiredelay ) );
            var_11 = pickrandomtargetpoint( var_7, var_4.strikeradius );
            var_9 = magicbullet( var_4.projectilename, var_8, var_11, var_0 );
        }
    }
    else
        iprintln( "Mortar LOS blocked!" );
}

pickrandomtargetpoint( var_0, var_1 )
{
    var_2 = randomfloatrange( -1 * var_1, var_1 );
    var_3 = randomfloatrange( -1 * var_1, var_1 );
    return var_0 + ( var_2, var_3, 0 );
}
