# Wave Unit Count

Grammar — Get the number of units in wave w
FlagsNative | Function

Returns the number of units in a wave.

# Arguments

  • wave — Wave

Returns — int

native int AIWaveUnitCount(wave w);

Category: AI Advanced / Waves / Functions

# Examples

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/voidprologue/voidprologue01.sc2map/MapScript.galaxy:4226

        TriggerExecute(gt_Kerrigan07Wave, true, true);
        Wait(gv_waveCooldownTime, c_timeGame);
        while (!((AIWaveUnitCount(gv_currentWave) < 15))) {
            Wait(1.0, c_timeGame);
        }

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/voidprologue/voidprologue01.sc2mapMapScript.galaxy:4226

        TriggerExecute(gt_Kerrigan07Wave, true, true);
        Wait(gv_waveCooldownTime, c_timeGame);
        while (!((AIWaveUnitCount(gv_currentWave) < 15))) {
            Wait(1.0, c_timeGame);
        }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeAI.galaxy:322


    // first offer it to the attack wave if that wave has some units in it
    if (AIWaveUnitCount(attackWave) >= 4) {
        if (AIWaveDetectorCount(attackWave) == 0) {
            AIWaveAddUnitPriority(attackWave, u, c_prioWavePeon);

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeAI.galaxy:343


    // let the attack wave claim a second one
    if (AIWaveUnitCount(attackWave) >= 4) {
        if (AIWaveDetectorCount(attackWave) < 2) {
            AIWaveAddUnitPriority(attackWave, u, c_prioWavePeon);

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeHighAI.galaxy:165


    if (AIGetCoopFlag(player, c_coopWaveAttacker)) {
        if (AIWaveUnitCount(AIWaveGet(player, c_waveAttack)) > 0) {
            return;
        }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeHighAI.galaxy:168

            return;
        }
        if (AIWaveUnitCount(AIWaveGet(player, c_waveMain)) < 8) {
            return;
        }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeLowAI.galaxy:120

    }
    if (sendAttack) {
        waveCount = AIWaveUnitCount(AIWaveGet(player, c_waveMain)) + AIWaveUnitCount(AIWaveGet(player, c_waveAttack));
        desiredArmyCount = AIGetStockArmyCount(player);
        if (waveCount < desiredArmyCount/2) {

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeLowAI.galaxy:120

    }
    if (sendAttack) {
        waveCount = AIWaveUnitCount(AIWaveGet(player, c_waveMain)) + AIWaveUnitCount(AIWaveGet(player, c_waveAttack));
        desiredArmyCount = AIGetStockArmyCount(player);
        if (waveCount < desiredArmyCount/2) {

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeLowAI.galaxy:168

            activateNextWave = false; // wait for the AI to activate
        }
        if (AIWaveUnitCount(AIWaveGet(player, c_waveAttack)) > 0) {
            activateNextWave = false;
        }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeLowAI.galaxy:171

            activateNextWave = false;
        }
        else if (AIWaveUnitCount(AIWaveGet(player, c_waveMain)) < 8) {
            activateNextWave = false;
        }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:58

        player,
        "wave="         + name                                          +
        ", units="      + IntToString(AIWaveUnitCount(w))               +
        ", state="      + WaveStateName(AIWaveState(w))                 +
        ", ratio="      + IntToString(AIWaveEvalRatio(w, c_evalRange))  +

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:155

void AIWaveMain (int player, wave w) {
    unit obstruction = null;
    int count = AIWaveUnitCount(w);
    int state = AIWaveState(w);
    int attackState = AIState(player, e_attackState);

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:226


    if (!AIGetFlag(player, e_flagsDiversion)) {
        if (AIWaveUnitCount(w) != 0) {
            if (type == c_waveDivert1) {
                AIWaveMerge(player, c_waveDivert1, c_waveAttack);

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:349

    // See if the clear obstruction wave is already full
    waveClob = AIWaveGet(player, c_waveClearObs);
    countClob = AIWaveUnitCount(waveClob);
    if (countClob >= 4) {
        return false;

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:356

    // If the attack wave is getting weak, keep units available for it instead
    waveAtck = AIWaveGet(player, c_waveAttack);
    countAtck = AIWaveUnitCount(waveAtck);
    evalAtck = AIWaveEvalRatio(waveAtck, c_evalRange);
    if (countAtck > 0 && evalAtck < 90) {

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:401


    waveAttack = AIWaveGet(player, c_waveAttack);
    if (AIWaveUnitCount(waveAttack) == 0) {
        return false;
    }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:426


    waveAttack = AIWaveGet(player, c_waveAttack);
    if (AIWaveUnitCount(waveAttack) == 0) {
        return c_nullPoint;
    }

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:758


    else if (state == e_attackState_Idle) {
        count = AIWaveUnitCount(w) + AIWaveUnitCount(AIWaveGet(player, c_waveMain));

        if ((AIWaveGetTimeSinceRetreat(w) > 120) && (AIGetUserInt(player, c_delayNextAttack) < AIGetTime())) {            

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:758


    else if (state == e_attackState_Idle) {
        count = AIWaveUnitCount(w) + AIWaveUnitCount(AIWaveGet(player, c_waveMain));

        if ((AIWaveGetTimeSinceRetreat(w) > 120) && (AIGetUserInt(player, c_delayNextAttack) < AIGetTime())) {            

mods/core.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:806

    }

    if (AIWaveUnitCount(w) < 1) {
        return;
    }

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMI.galaxy:13147

            lv_playerWavesIter = 0;
            for ( ; ( (auto7A411C1C_ai >= 0 && lv_playerWavesIter <= auto7A411C1C_ae) || (auto7A411C1C_ai < 0 && lv_playerWavesIter >= auto7A411C1C_ae) ) ; lv_playerWavesIter += auto7A411C1C_ai ) {
                if ((AIWaveUnitCount(libCOMI_gv_cM_CoopAIPlayer_AttackWaves[lv_playerIter][lv_playerWavesIter]) > 0)) {
                    autoADEF27AE_g = AIWaveGetUnits(libCOMI_gv_cM_CoopAIPlayer_AttackWaves[lv_playerIter][lv_playerWavesIter]);
                    autoADEF27AE_u = UnitGroupCount(autoADEF27AE_g, c_unitCountAll);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/MeleeAI.galaxy:322


    // first offer it to the attack wave if that wave has some units in it
    if (AIWaveUnitCount(attackWave) >= 4) {
        if (AIWaveDetectorCount(attackWave) == 0) {
            AIWaveAddUnitPriority(attackWave, u, c_prioWavePeon);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/MeleeAI.galaxy:343


    // let the attack wave claim a second one
    if (AIWaveUnitCount(attackWave) >= 4) {
        if (AIWaveDetectorCount(attackWave) < 2) {
            AIWaveAddUnitPriority(attackWave, u, c_prioWavePeon);

mods/void.sc2modbase.sc2data/TriggerLibs/MeleeHighAI.galaxy:165


    if (AIGetCoopFlag(player, c_coopWaveAttacker)) {
        if (AIWaveUnitCount(AIWaveGet(player, c_waveAttack)) > 0) {
            return;
        }

mods/void.sc2modbase.sc2data/TriggerLibs/MeleeHighAI.galaxy:168

            return;
        }
        if (AIWaveUnitCount(AIWaveGet(player, c_waveMain)) < 8) {
            return;
        }

mods/warcoop/warcoopdata.sc2modbase.sc2data/TriggerLibs/WarCoopData.galaxy:2941


    // Implementation
    if ((AIWaveUnitCount(lp_wave) == 0)) {
        return true;
    }

mods/warcoop/warcoopdata.sc2modbase.sc2data/TriggerLibs/WarCoopData.galaxy:2948

    lv_ping = PingLastCreated();
    PingSetScale(lv_ping, lp_scale);
    while ((AIWaveUnitCount(lp_wave) > 0)) {
        PingSetPosition(lv_ping, UnitGroupCenterOfGroup(AIWaveGetUnits(lp_wave)));
        Wait(1.0, c_timeGame);

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:188

        player,
        "wave="         + name                                          +
        ", units="      + IntToString(AIWaveUnitCount(w))               +
        ", state="      + WaveStateName(AIWaveState(w))                 +
        ", ratio="      + IntToString(AIWaveEvalRatio(w, c_evalRange))  +

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:251

void AIWaveMain (int player, wave w) {
    unit obstruction = null;
    int count = AIWaveUnitCount(w);
    int state = AIWaveState(w);
    int attackState = AIState(player, e_attackState);

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:315


    if (!AIGetFlag(player, e_flagsDiversion)) {
        if (AIWaveUnitCount(w) != 0) {
            if (type == c_waveDivert1) {
                AIWaveMerge(player, c_waveDivert1, c_waveAttack);

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:432

    // See if the clear obstruction wave is already full
    waveClob = AIWaveGet(player, c_waveClearObs);
    countClob = AIWaveUnitCount(waveClob);
    if (countClob >= 4) {
        return false;

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:439

    // If the attack wave is getting weak, keep units available for it instead
    waveAtck = AIWaveGet(player, c_waveAttack);
    countAtck = AIWaveUnitCount(waveAtck);
    evalAtck = AIWaveEvalRatio(waveAtck, c_evalRange);
    if (countAtck > 0 && evalAtck < 90) {

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:491


    waveAttack = AIWaveGet(player, c_waveAttack);
    if (AIWaveUnitCount(waveAttack) == 0) {
        return false;
    }

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:516


    waveAttack = AIWaveGet(player, c_waveAttack);
    if (AIWaveUnitCount(waveAttack) == 0) {
        return c_nullPoint;
    }

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:851


    else if (state == e_attackState_Idle) {
        count = AIWaveUnitCount(w) + AIWaveUnitCount(AIWaveGet(player, c_waveMain));

        if ((AIWaveGetTimeSinceRetreat(w) > 2) && (AIGetUserInt(player, c_delayNextAttack) < AIGetTime())) {            

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:851


    else if (state == e_attackState_Idle) {
        count = AIWaveUnitCount(w) + AIWaveUnitCount(AIWaveGet(player, c_waveMain));

        if ((AIWaveGetTimeSinceRetreat(w) > 2) && (AIGetUserInt(player, c_delayNextAttack) < AIGetTime())) {            

mods/warcoop/warmeleeai.sc2modbase.sc2data/TriggerLibs/MeleeWaveAI.galaxy:902

    }

    if (AIWaveUnitCount(w) < 1) {
        return;
    }