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

main()
{
    if ( getdvar( "mapname" ) == "mp_background" )
        return;

    maps\mp\gametypes\_globallogic::init();
    maps\mp\gametypes\_callbacksetup::setupcallbacks();
    maps\mp\gametypes\_globallogic::setupcallbacks();

    if ( isusingmatchrulesdata() )
    {
        level.initializematchrules = ::initializematchrules;
        [[ level.initializematchrules ]]();
        level thread maps\mp\_utility::reinitializematchrulesonmigration();
    }
    else
    {
        maps\mp\_utility::registertimelimitdvar( level.gametype, 30 );
        maps\mp\_utility::registerscorelimitdvar( level.gametype, 300 );
        maps\mp\_utility::registerroundlimitdvar( level.gametype, 1 );
        maps\mp\_utility::registerwinlimitdvar( level.gametype, 1 );
        maps\mp\_utility::registernumlivesdvar( level.gametype, 0 );
        maps\mp\_utility::registerhalftimedvar( level.gametype, 0 );
        level.matchrules_damagemultiplier = 0;
        level.matchrules_vampirism = 0;
    }

    level.teambased = 1;
    level.onstartgametype = ::onstartgametype;
    level.getspawnpoint = ::getspawnpoint;
    level.onplayerkilled = ::onplayerkilled;
    level.initgametypeawards = ::initgametypeawards;
    level.onspawnplayer = ::onspawnplayer;
    level.lastcaptime = gettime();
    level.alliescapturing = [];
    level.axiscapturing = [];

    if ( level.matchrules_damagemultiplier || level.matchrules_vampirism )
        level.modifyplayerdamage = maps\mp\gametypes\_damage::gamemodemodifyplayerdamage;

    game["dialog"]["gametype"] = "domination";

    if ( getdvarint( "g_hardcore" ) )
        game["dialog"]["gametype"] = "hc_" + game["dialog"]["gametype"];
    else if ( getdvarint( "camera_thirdPerson" ) )
        game["dialog"]["gametype"] = "thirdp_" + game["dialog"]["gametype"];
    else if ( getdvarint( "scr_diehard" ) )
        game["dialog"]["gametype"] = "dh_" + game["dialog"]["gametype"];
    else if ( getdvarint( "scr_" + level.gametype + "_promode" ) )
        game["dialog"]["gametype"] = game["dialog"]["gametype"] + "_pro";

    game["dialog"]["offense_obj"] = "capture_objs";
    game["dialog"]["defense_obj"] = "capture_objs";
    thread onplayerconnect();
}

initializematchrules()
{
    maps\mp\_utility::setcommonrulesfrommatchrulesdata();

    if ( getdvarint( "scr_playlist_type", 0 ) == 1 || maps\mp\_utility::ismlgmatch() )
    {
        setdynamicdvar( "scr_dom_roundswitch", 1 );
        maps\mp\_utility::registerroundswitchdvar( "dom", 1, 0, 1 );
        setdynamicdvar( "scr_dom_roundlimit", 2 );
        maps\mp\_utility::registerroundlimitdvar( "dom", 2 );
        setdynamicdvar( "scr_dom_winlimit", 0 );
        maps\mp\_utility::registerwinlimitdvar( "dom", 0 );
    }
    else
    {
        setdynamicdvar( "scr_dom_roundlimit", 1 );
        maps\mp\_utility::registerroundlimitdvar( "dom", 1 );
        setdynamicdvar( "scr_dom_winlimit", 1 );
        maps\mp\_utility::registerwinlimitdvar( "dom", 1 );
    }

    setdynamicdvar( "scr_dom_halftime", 0 );
    maps\mp\_utility::registerhalftimedvar( "dom", 0 );
    setdynamicdvar( "scr_dom_promode", 0 );
}

onstartgametype()
{
    maps\mp\_utility::setobjectivetext( "allies", &"OBJECTIVES_DOM" );
    maps\mp\_utility::setobjectivetext( "axis", &"OBJECTIVES_DOM" );

    if ( level.splitscreen )
    {
        maps\mp\_utility::setobjectivescoretext( "allies", &"OBJECTIVES_DOM" );
        maps\mp\_utility::setobjectivescoretext( "axis", &"OBJECTIVES_DOM" );
    }
    else
    {
        maps\mp\_utility::setobjectivescoretext( "allies", &"OBJECTIVES_DOM_SCORE" );
        maps\mp\_utility::setobjectivescoretext( "axis", &"OBJECTIVES_DOM_SCORE" );
    }

    maps\mp\_utility::setobjectivehinttext( "allies", &"OBJECTIVES_DOM_HINT" );
    maps\mp\_utility::setobjectivehinttext( "axis", &"OBJECTIVES_DOM_HINT" );
    setclientnamemode( "auto_change" );

    if ( !isdefined( game["switchedsides"] ) )
        game["switchedsides"] = 0;

    level.flagbasefxid["neutral"] = loadfx( "vfx/gameplay/mp/core/vfx_marker_base_grey" );
    level.flagbasefxid["friendly"] = loadfx( "vfx/gameplay/mp/core/vfx_marker_base_cyan" );
    level.flagbasefxid["enemy"] = loadfx( "vfx/gameplay/mp/core/vfx_marker_base_orange" );
    initspawns();
    var_0[0] = "dom";
    maps\mp\gametypes\_gameobjects::main( var_0 );
    thread domflags();
    thread updatedomscores();
}

initspawns()
{
    level.spawnmins = ( 0, 0, 0 );
    level.spawnmaxs = ( 0, 0, 0 );
    maps\mp\gametypes\_spawnlogic::addstartspawnpoints( "mp_dom_spawn_allies_start" );
    maps\mp\gametypes\_spawnlogic::addstartspawnpoints( "mp_dom_spawn_axis_start" );
    maps\mp\gametypes\_spawnlogic::addspawnpoints( "allies", "mp_dom_spawn" );
    maps\mp\gametypes\_spawnlogic::addspawnpoints( "axis", "mp_dom_spawn" );
    level.mapcenter = maps\mp\gametypes\_spawnlogic::findboxcenter( level.spawnmins, level.spawnmaxs );
    setmapcenter( level.mapcenter );
}

getspawnpoint()
{
    var_0 = self.pers["team"];
    var_1 = maps\mp\_utility::getotherteam( var_0 );

    if ( level.usestartspawns )
    {
        if ( game["switchedsides"] )
        {
            var_2 = maps\mp\gametypes\_spawnlogic::getspawnpointarray( "mp_dom_spawn_" + var_1 + "_start" );
            var_3 = maps\mp\gametypes\_spawnlogic::getspawnpoint_startspawn( var_2 );
        }
        else
        {
            var_2 = maps\mp\gametypes\_spawnlogic::getspawnpointarray( "mp_dom_spawn_" + var_0 + "_start" );
            var_3 = maps\mp\gametypes\_spawnlogic::getspawnpoint_startspawn( var_2 );
        }
    }
    else
    {
        var_4 = getteamdompoints( var_0 );
        var_5 = maps\mp\_utility::getotherteam( var_0 );
        var_6 = getteamdompoints( var_5 );
        var_7 = getperfereddompoints( var_4, var_6 );
        var_2 = maps\mp\gametypes\_spawnlogic::getteamspawnpoints( var_0 );
        var_3 = maps\mp\gametypes\_spawnscoring::getspawnpoint_domination( var_2, var_7 );
    }

    return var_3;
}

getteamdompoints( var_0 )
{
    var_1 = [];

    foreach ( var_3 in level.domflags )
    {
        if ( var_3.ownerteam == var_0 )
            var_1[var_1.size] = var_3;
    }

    return var_1;
}

getperfereddompoints( var_0, var_1 )
{
    var_2 = [];
    var_2[0] = 0;
    var_2[1] = 0;
    var_2[2] = 0;
    var_3 = self.pers["team"];

    if ( var_0.size == level.domflags.size )
    {
        var_4 = var_3;
        var_5 = level.bestspawnflag[var_3];
        var_2[var_5.useobj.dompointnumber] = 1;
        return var_2;
    }

    if ( var_0.size == 1 && var_1.size == 2 && !maps\mp\_utility::isanymlgmatch() )
    {
        var_6 = maps\mp\_utility::getotherteam( self.team );
        var_7 = maps\mp\gametypes\_gamescore::_getteamscore( var_6 ) - maps\mp\gametypes\_gamescore::_getteamscore( self.team );

        if ( var_7 > 15 )
        {
            var_8 = gettimesincedompointcapture( var_0[0] );
            var_9 = gettimesincedompointcapture( var_1[0] );
            var_10 = gettimesincedompointcapture( var_1[1] );

            if ( var_8 > 40000 && var_9 > 40000 && var_10 > 40000 )
                return var_2;
        }
    }

    if ( var_0.size > 0 )
    {
        foreach ( var_12 in var_0 )
            var_2[var_12.dompointnumber] = 1;

        return var_2;
    }

    if ( var_0.size == 0 )
    {
        var_4 = var_3;
        var_5 = level.bestspawnflag[var_4];

        if ( var_1.size > 0 && var_1.size < level.domflags.size )
        {
            var_5 = getunownedflagneareststart( var_4 );
            level.bestspawnflag[var_4] = var_5;
        }

        var_2[var_5.useobj.dompointnumber] = 1;
        return var_2;
    }

    return var_2;
}

gettimesincedompointcapture( var_0 )
{
    return gettime() - var_0.capturetime;
}

domflags()
{
    level.laststatus["allies"] = 0;
    level.laststatus["axis"] = 0;
    game["flagmodels"] = [];
    game["flagmodels"]["neutral"] = "prop_flag_neutral";
    game["flagmodels"]["allies"] = maps\mp\gametypes\_teams::getteamflagmodel( "allies" );
    game["flagmodels"]["axis"] = maps\mp\gametypes\_teams::getteamflagmodel( "axis" );
    var_0 = getentarray( "flag_primary", "targetname" );
    var_1 = getentarray( "flag_secondary", "targetname" );

    if ( var_0.size + var_1.size < 2 )
        return;

    level.flags = [];

    for ( var_2 = 0; var_2 < var_0.size; var_2++ )
        level.flags[level.flags.size] = var_0[var_2];

    for ( var_2 = 0; var_2 < var_1.size; var_2++ )
        level.flags[level.flags.size] = var_1[var_2];

    level.domflags = [];

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

        if ( isdefined( var_3.target ) )
            var_4[0] = getent( var_3.target, "targetname" );
        else
        {
            var_4[0] = spawn( "script_model", var_3.origin );
            var_4[0].angles = var_3.angles;
        }

        var_5 = maps\mp\gametypes\_gameobjects::createuseobject( "neutral", var_3, var_4, ( 0, 0, 100 ) );
        var_5 maps\mp\gametypes\_gameobjects::allowuse( "enemy" );
        var_5 maps\mp\gametypes\_gameobjects::setusetime( 10 );
        var_5 maps\mp\gametypes\_gameobjects::setusetext( &"MP_SECURING_POSITION" );
        var_6 = var_5 maps\mp\gametypes\_gameobjects::getlabel();
        var_5.label = var_6;
        var_5 maps\mp\gametypes\_gameobjects::set2dicon( "friendly", "waypoint_defend" + var_6 );
        var_5 maps\mp\gametypes\_gameobjects::set3dicon( "friendly", "waypoint_defend" + var_6 );
        var_5 maps\mp\gametypes\_gameobjects::set2dicon( "enemy", "waypoint_captureneutral" + var_6 );
        var_5 maps\mp\gametypes\_gameobjects::set3dicon( "enemy", "waypoint_captureneutral" + var_6 );
        var_5 maps\mp\gametypes\_gameobjects::setvisibleteam( "any" );
        var_5.onuse = ::onuse;
        var_5.onbeginuse = ::onbeginuse;
        var_5.onuseupdate = ::onuseupdate;
        var_5.onenduse = ::onenduse;
        var_5.nousebar = 1;
        var_5.id = "domFlag";
        var_5.firstcapture = 1;
        var_7 = var_4[0].origin + ( 0, 0, 32 );
        var_8 = var_4[0].origin + ( 0, 0, -32 );
        var_9 = bullettrace( var_7, var_8, 0, undefined );
        var_5.baseeffectpos = var_9["position"];
        var_10 = vectortoangles( var_9["normal"] );
        var_5.baseeffectforward = anglestoforward( var_10 );
        var_5 thread setflagneutral();
        level.flags[var_2].useobj = var_5;
        var_5.levelflag = level.flags[var_2];
        level.domflags[level.domflags.size] = var_5;
    }

    var_11 = maps\mp\gametypes\_spawnlogic::getspawnpointarray( "mp_dom_spawn_axis_start" );
    var_12 = maps\mp\gametypes\_spawnlogic::getspawnpointarray( "mp_dom_spawn_allies_start" );
    level.startpos["allies"] = var_12[0].origin;
    level.startpos["axis"] = var_11[0].origin;
    level.bestspawnflag = [];
    level.bestspawnflag["allies"] = getunownedflagneareststart( "allies", undefined );
    level.bestspawnflag["axis"] = getunownedflagneareststart( "axis", level.bestspawnflag["allies"] );
    flagsetup();
}

getunownedflagneareststart( var_0, var_1 )
{
    var_2 = undefined;
    var_3 = undefined;

    for ( var_4 = 0; var_4 < level.flags.size; var_4++ )
    {
        var_5 = level.flags[var_4];

        if ( var_5 getflagteam() != "neutral" )
            continue;

        var_6 = distancesquared( var_5.origin, level.startpos[var_0] );

        if ( ( !isdefined( var_1 ) || var_5 != var_1 ) && ( !isdefined( var_2 ) || var_6 < var_3 ) )
        {
            var_3 = var_6;
            var_2 = var_5;
        }
    }

    return var_2;
}

onbeginuse( var_0 )
{
    var_1 = maps\mp\gametypes\_gameobjects::getownerteam();
    self.didstatusnotify = 0;

    if ( var_1 == "neutral" )
    {
        statusdialog( "securing" + self.label, var_0.team );

        if ( !self.firstcapture )
        {
            if ( self.curprogress == 0 )
                maps\mp\gametypes\_gameobjects::setusetime( 5.0 );
        }
    }
    else
    {
        maps\mp\gametypes\_gameobjects::setusetime( 10 );

        if ( var_1 == "allies" )
        {
            level.alliescapturing[level.alliescapturing.size] = self.label;
            var_2 = "axis";
            return;
        }

        level.axiscapturing[level.axiscapturing.size] = self.label;
        var_2 = "allies";
    }
}

onuseupdate( var_0, var_1, var_2 )
{
    var_3 = maps\mp\gametypes\_gameobjects::getownerteam();

    if ( var_1 > 0.05 && var_2 && !self.didstatusnotify )
    {
        if ( var_3 == "neutral" )
        {
            statusdialog( "securing" + self.label, var_0 );
            self.prevownerteam = maps\mp\_utility::getotherteam( var_0 );
        }
        else
        {
            statusdialog( "losing" + self.label, var_3, 1 );
            statusdialog( "securing" + self.label, var_0 );
        }

        maps\mp\gametypes\_gameobjects::set2dicon( "enemy", "waypoint_taking" + self.label );
        maps\mp\gametypes\_gameobjects::set3dicon( "enemy", "waypoint_taking" + self.label );
        maps\mp\gametypes\_gameobjects::set2dicon( "friendly", "waypoint_losing" + self.label );
        maps\mp\gametypes\_gameobjects::set3dicon( "friendly", "waypoint_losing" + self.label );
        self.didstatusnotify = 1;
    }
    else if ( var_1 > 0.49 && var_2 && self.didstatusnotify && var_3 != "neutral" )
    {
        thread setflagneutral();
        statusdialog( "lost" + self.label, var_3, 1 );
        maps\mp\_utility::playsoundonplayers( "mp_dom_flag_lost", var_3 );
        level.lastcaptime = gettime();
        thread giveflagassistedcapturepoints( self.touchlist[var_0] );
    }
}

giveflagassistedcapturepoints( var_0 )
{
    level endon( "game_ended" );
    var_1 = getarraykeys( var_0 );

    for ( var_2 = 0; var_2 < var_1.size; var_2++ )
    {
        var_3 = var_0[var_1[var_2]].player;

        if ( !isdefined( var_3 ) )
            continue;

        if ( isdefined( var_3.owner ) )
            var_3 = var_3.owner;

        if ( !isplayer( var_3 ) )
            continue;

        var_3 maps\mp\_events::giveobjectivepointstreaks();
        wait 0.05;
    }
}

statusdialog( var_0, var_1, var_2 )
{
    var_3 = gettime();

    if ( gettime() < level.laststatus[var_1] + 5000 && ( !isdefined( var_2 ) || !var_2 ) )
        return;

    thread delayedleaderdialog( var_0, var_1 );
    level.laststatus[var_1] = gettime();
}

onenduse( var_0, var_1, var_2 )
{
    if ( isplayer( var_1 ) )
    {
        var_1 setclientomnvar( "ui_dom_securing", 0 );
        var_1.ui_dom_securing = undefined;
    }

    var_3 = maps\mp\gametypes\_gameobjects::getownerteam();

    if ( var_3 != "neutral" )
    {
        maps\mp\gametypes\_gameobjects::set2dicon( "enemy", "waypoint_capture" + self.label );
        maps\mp\gametypes\_gameobjects::set3dicon( "enemy", "waypoint_capture" + self.label );
        maps\mp\gametypes\_gameobjects::set2dicon( "friendly", "waypoint_defend" + self.label );
        maps\mp\gametypes\_gameobjects::set3dicon( "friendly", "waypoint_defend" + self.label );
    }
    else
    {
        maps\mp\gametypes\_gameobjects::set2dicon( "enemy", "waypoint_captureneutral" + self.label );
        maps\mp\gametypes\_gameobjects::set3dicon( "enemy", "waypoint_captureneutral" + self.label );
        maps\mp\gametypes\_gameobjects::set2dicon( "friendly", "waypoint_captureneutral" + self.label );
        maps\mp\gametypes\_gameobjects::set3dicon( "friendly", "waypoint_captureneutral" + self.label );
    }

    if ( var_0 == "allies" )
        common_scripts\utility::array_remove( level.alliescapturing, self.label );
    else
        common_scripts\utility::array_remove( level.axiscapturing, self.label );
}

resetflagbaseeffect()
{
    var_0 = maps\mp\gametypes\_gameobjects::getownerteam();

    if ( var_0 == "neutral" )
        playflagneutralfx();
    else
    {
        foreach ( var_2 in level.players )
            showcapturedbaseeffecttoplayer( var_0, var_2 );
    }
}

onuse( var_0 )
{
    var_1 = var_0.team;
    var_2 = maps\mp\gametypes\_gameobjects::getownerteam();
    self.capturetime = gettime();
    self.firstcapture = 0;
    setflagcaptured( var_1 );
    level.usestartspawns = 0;

    if ( var_2 == "neutral" )
    {
        var_3 = maps\mp\_utility::getotherteam( var_1 );
        thread maps\mp\_utility::printandsoundoneveryone( var_1, var_3, undefined, undefined, "mp_dom_flag_captured", undefined, var_0 );

        if ( getteamflagcount( var_1 ) < level.flags.size )
        {
            statusdialog( "secured" + self.label, var_1, 1 );
            statusdialog( "enemy_has" + self.label, var_3, 1 );
        }
        else
        {
            statusdialog( "secure_all", var_1 );
            statusdialog( "lost_all", var_3 );

            foreach ( var_5 in level.players )
            {
                if ( var_5.team == var_1 )
                    var_5 maps\mp\gametypes\_missions::processchallenge( "ch_domdom" );
            }
        }
    }

    var_0 maps\mp\_events::giveobjectivepointstreaks();
    thread giveflagcapturexp( self.touchlist[var_1] );
}

giveflagcapturexp( var_0 )
{
    level endon( "game_ended" );
    var_1 = maps\mp\gametypes\_gameobjects::getearliestclaimplayer();

    if ( isdefined( var_1.owner ) )
        var_1 = var_1.owner;

    level.lastcaptime = gettime();

    if ( isplayer( var_1 ) )
    {
        level thread maps\mp\_utility::teamplayercardsplash( "callout_securedposition" + self.label, var_1 );
        var_1 thread maps\mp\_matchdata::loggameevent( "capture", var_1.origin );
    }

    var_2 = getarraykeys( var_0 );

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

        if ( isdefined( var_4.owner ) )
            var_4 = var_4.owner;

        if ( !isplayer( var_4 ) )
            continue;

        var_4 thread maps\mp\gametypes\_hud_message::splashnotify( "capture", maps\mp\gametypes\_rank::getscoreinfovalue( "capture" ) );
        var_4 thread updatecpm();
        var_4 thread maps\mp\gametypes\_rank::giverankxp( "capture", maps\mp\gametypes\_rank::getscoreinfovalue( "capture" ) * var_4 getcapxpscale() );
        maps\mp\gametypes\_gamescore::giveplayerscore( "capture", var_4 );
        var_4 maps\mp\_utility::incplayerstat( "pointscaptured", 1 );
        var_4 maps\mp\_utility::incpersstat( "captures", 1 );
        var_4 maps\mp\gametypes\_persistence::statsetchild( "round", "captures", var_4.pers["captures"] );
        var_4 maps\mp\gametypes\_missions::processchallenge( "ch_domcap" );
        var_4 maps\mp\_utility::setextrascore0( var_4.pers["captures"] );

        if ( var_4 != var_1 )
            var_4 maps\mp\_events::giveobjectivepointstreaks();

        wait 0.05;
    }
}

delayedleaderdialog( var_0, var_1 )
{
    level endon( "game_ended" );
    wait 0.1;
    maps\mp\_utility::waittillslowprocessallowed();
    maps\mp\_utility::leaderdialog( var_0, var_1 );
}

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

    while ( !level.gameended )
    {
        var_0 = getowneddomflags();

        if ( var_0.size )
        {
            for ( var_1 = 1; var_1 < var_0.size; var_1++ )
            {
                var_2 = var_0[var_1];
                var_3 = gettime() - var_2.capturetime;

                for ( var_4 = var_1 - 1; var_4 >= 0 && var_3 > gettime() - var_0[var_4].capturetime; var_4-- )
                    var_0[var_4 + 1] = var_0[var_4];

                var_0[var_4 + 1] = var_2;
            }

            foreach ( var_2 in var_0 )
            {
                var_6 = var_2 maps\mp\gametypes\_gameobjects::getownerteam();
                maps\mp\gametypes\_gamescore::giveteamscoreforobjective( var_6, 1 );
            }
        }

        var_8 = gettime() - level.lastcaptime;

        if ( maps\mp\_utility::matchmakinggame() && var_0.size < 2 && var_8 > 120000 )
        {
            level.finalkillcam_winner = "none";
            thread maps\mp\gametypes\_gamelogic::endgame( "none", game["end_reason"]["time_limit_reached"] );
            return;
        }

        wait 5.0;
        maps\mp\gametypes\_hostmigration::waittillhostmigrationdone();
    }
}

onplayerkilled( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9 )
{
    if ( !isplayer( var_1 ) || var_1.team == self.team )
        return;

    var_10 = 0;
    var_11 = 0;
    var_12 = self;

    foreach ( var_14 in var_12.touchtriggers )
    {
        if ( var_14 != level.flags[0] && var_14 != level.flags[1] && var_14 != level.flags[2] )
            continue;

        var_15 = var_14.useobj.ownerteam;
        var_16 = var_12.team;

        if ( var_15 == "neutral" )
            continue;

        if ( var_16 == var_15 )
        {
            var_10 = 1;
            var_1 thread maps\mp\gametypes\_hud_message::splashnotify( "assault", maps\mp\gametypes\_rank::getscoreinfovalue( "assault" ) );
            var_1 thread maps\mp\gametypes\_rank::giverankxp( "assault" );
            maps\mp\gametypes\_gamescore::giveplayerscore( "assault", var_1 );
            thread maps\mp\_matchdata::logkillevent( var_9, "defending" );
            continue;
        }

        var_11 = 1;
        var_1 thread maps\mp\gametypes\_hud_message::splashnotify( "defend", maps\mp\gametypes\_rank::getscoreinfovalue( "defend" ) );
        var_1 thread maps\mp\gametypes\_rank::giverankxp( "defend" );
        maps\mp\gametypes\_gamescore::giveplayerscore( "defend", var_1 );
        var_1 maps\mp\_utility::incpersstat( "defends", 1 );
        var_1 maps\mp\gametypes\_persistence::statsetchild( "round", "defends", var_1.pers["defends"] );
        var_1 maps\mp\gametypes\_missions::processchallenge( "ch_domprotector" );
        thread maps\mp\_matchdata::logkillevent( var_9, "assaulting" );
    }

    foreach ( var_14 in var_1.touchtriggers )
    {
        if ( var_14 != level.flags[0] && var_14 != level.flags[1] && var_14 != level.flags[2] )
            continue;

        var_15 = var_14.useobj.ownerteam;
        var_19 = var_1.team;

        if ( var_15 == "neutral" )
            continue;

        if ( var_19 != var_15 )
        {
            if ( !var_10 )
                var_1 thread maps\mp\gametypes\_hud_message::splashnotify( "assault", maps\mp\gametypes\_rank::getscoreinfovalue( "assault" ) );

            var_1 thread maps\mp\gametypes\_rank::giverankxp( "assault" );
            maps\mp\gametypes\_gamescore::giveplayerscore( "assault", var_1 );
            thread maps\mp\_matchdata::logkillevent( var_9, "defending" );
        }
    }

    foreach ( var_14 in level.flags )
    {
        var_15 = var_14.useobj.ownerteam;
        var_19 = var_1.team;
        var_22 = distancesquared( var_14.origin, var_12.origin );
        var_23 = 90000;

        if ( var_19 == var_15 && var_22 < var_23 )
        {
            if ( !var_11 )
                var_1 thread maps\mp\gametypes\_hud_message::splashnotify( "defend", maps\mp\gametypes\_rank::getscoreinfovalue( "defend" ) );

            var_1 thread maps\mp\gametypes\_rank::giverankxp( "defend" );
            maps\mp\gametypes\_gamescore::giveplayerscore( "defend", var_1 );
            var_1 maps\mp\_utility::incpersstat( "defends", 1 );
            var_1 maps\mp\gametypes\_persistence::statsetchild( "round", "defends", var_1.pers["defends"] );
            thread maps\mp\_matchdata::logkillevent( var_9, "assaulting" );
        }
    }
}

getowneddomflags()
{
    var_0 = [];

    foreach ( var_2 in level.domflags )
    {
        if ( var_2 maps\mp\gametypes\_gameobjects::getownerteam() != "neutral" && isdefined( var_2.capturetime ) )
            var_0[var_0.size] = var_2;
    }

    return var_0;
}

getteamflagcount( var_0 )
{
    var_1 = 0;

    for ( var_2 = 0; var_2 < level.flags.size; var_2++ )
    {
        if ( level.domflags[var_2] maps\mp\gametypes\_gameobjects::getownerteam() == var_0 )
            var_1++;
    }

    return var_1;
}

getflagteam()
{
    return self.useobj maps\mp\gametypes\_gameobjects::getownerteam();
}

flagsetup()
{
    foreach ( var_1 in level.domflags )
    {
        switch ( var_1.label )
        {
            case "_a":
                var_1.dompointnumber = 0;
                break;
            case "_b":
                var_1.dompointnumber = 1;
                break;
            case "_c":
                var_1.dompointnumber = 2;
                break;
        }
    }

    var_3 = maps\mp\gametypes\_spawnlogic::getspawnpointarray( "mp_dom_spawn" );

    foreach ( var_5 in var_3 )
    {
        var_5.dompointa = 0;
        var_5.dompointb = 0;
        var_5.dompointc = 0;
        var_5.nearflagpoint = getnearestflagpoint( var_5 );

        switch ( var_5.nearflagpoint.useobj.dompointnumber )
        {
            case 0:
                var_5.dompointa = 1;
                break;
            case 1:
                var_5.dompointb = 1;
                break;
            case 2:
                var_5.dompointc = 1;
                break;
        }
    }
}

getnearestflagpoint( var_0 )
{
    var_1 = maps\mp\gametypes\_spawnlogic::ispathdataavailable();
    var_2 = undefined;
    var_3 = undefined;

    foreach ( var_5 in level.domflags )
    {
        var_6 = undefined;

        if ( var_1 )
            var_6 = getpathdist( var_0.origin, var_5.levelflag.origin, 999999 );

        if ( !isdefined( var_6 ) || var_6 == -1 )
            var_6 = distancesquared( var_5.levelflag.origin, var_0.origin );

        if ( !isdefined( var_2 ) || var_6 < var_3 )
        {
            var_2 = var_5;
            var_3 = var_6;
        }
    }

    return var_2.levelflag;
}

initgametypeawards()
{
    maps\mp\_awards::initstataward( "pointscaptured", 0, maps\mp\_awards::highestwins );
}

onspawnplayer()
{
    maps\mp\_utility::setextrascore0( 0 );

    if ( isdefined( self.pers["captures"] ) )
        maps\mp\_utility::setextrascore0( self.pers["captures"] );
}

updatecpm()
{
    if ( !isdefined( self.cpm ) )
    {
        self.numcaps = 0;
        self.cpm = 0;
    }

    self.numcaps++;

    if ( maps\mp\_utility::getminutespassed() < 1 )
        return;

    self.cpm = self.numcaps / maps\mp\_utility::getminutespassed();
}

getcapxpscale()
{
    if ( self.cpm < 4 )
        return 1;
    else
        return 0.25;
}

setflagneutral()
{
    self notify( "flag_neutral" );
    maps\mp\gametypes\_gameobjects::setownerteam( "neutral" );
    self.visuals[0] setmodel( game["flagmodels"]["neutral"] );

    foreach ( var_1 in level.players )
    {
        var_2 = var_1._domflageffect[self.label];

        if ( isdefined( var_2 ) )
            var_2 delete();
    }

    playflagneutralfx();
}

playflagneutralfx()
{
    if ( isdefined( self.neutralflagfx ) )
        self.neutralflagfx delete();

    self.neutralflagfx = spawnfx( level.flagbasefxid["neutral"], self.baseeffectpos, self.baseeffectforward );
    triggerfx( self.neutralflagfx );
}

setflagcaptured( var_0 )
{
    var_1 = maps\mp\gametypes\_gameobjects::getlabel();
    maps\mp\gametypes\_gameobjects::setownerteam( var_0 );
    maps\mp\gametypes\_gameobjects::set2dicon( "enemy", "waypoint_capture" + var_1 );
    maps\mp\gametypes\_gameobjects::set3dicon( "enemy", "waypoint_capture" + var_1 );
    maps\mp\gametypes\_gameobjects::set2dicon( "friendly", "waypoint_defend" + self.label );
    maps\mp\gametypes\_gameobjects::set3dicon( "friendly", "waypoint_defend" + self.label );
    self.visuals[0] setmodel( game["flagmodels"][var_0] );
    self.neutralflagfx delete();

    foreach ( var_3 in level.players )
        showcapturedbaseeffecttoplayer( var_0, var_3 );

    thread baseeffectswaitforjoined();
}

showcapturedbaseeffecttoplayer( var_0, var_1 )
{
    if ( isdefined( var_1._domflageffect[self.label] ) )
        var_1._domflageffect[self.label] delete();

    var_2 = undefined;
    var_3 = var_1.team;
    var_4 = var_1 ismlgspectator();

    if ( var_4 )
        var_3 = var_1 getmlgspectatorteam();
    else if ( var_3 == "spectator" )
        var_3 = "allies";

    if ( var_3 == var_0 )
        var_2 = spawnfxforclient( level.flagbasefxid["friendly"], self.baseeffectpos, var_1, self.baseeffectforward );
    else
        var_2 = spawnfxforclient( level.flagbasefxid["enemy"], self.baseeffectpos, var_1, self.baseeffectforward );

    var_1._domflageffect[self.label] = var_2;
    triggerfx( var_2 );
}

baseeffectswaitforjoined()
{
    level endon( "game_ended" );
    self endon( "flag_neutral" );

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

        if ( isdefined( var_0._domflageffect[self.label] ) )
        {
            var_0._domflageffect[self.label] delete();
            var_0._domflageffect[self.label] = undefined;
        }

        if ( var_0.team != "spectator" )
            showcapturedbaseeffecttoplayer( self.ownerteam, var_0 );
    }
}

onplayerconnect()
{
    for (;;)
    {
        level waittill( "connected", var_0 );
        var_0._domflageffect = [];
        var_0 thread ondisconnect();
        var_0 thread refreshfreecambasefx();
    }
}

ondisconnect()
{
    self waittill( "disconnect" );

    foreach ( var_1 in self._domflageffect )
    {
        if ( isdefined( var_1 ) )
            var_1 delete();
    }
}

refreshfreecambasefx()
{
    self endon( "disconnect" );
    level endon( "game_ended" );

    for (;;)
    {
        self waittill( "luinotifyserver", var_0, var_1 );

        if ( var_0 == "mlg_view_change" )
        {
            foreach ( var_3 in level.domflags )
            {
                if ( var_3.ownerteam != "neutral" )
                    var_3 showcapturedbaseeffecttoplayer( var_3.ownerteam, self );
            }
        }
    }
}
