# Tactical AI Filter Life Sort Reference

Grammar — Tactical AI Filter - sort units from filter by their current vitality vitality, sorting ones below threshold to the end
FlagsNative | Action

Sets the specified AI Filter to sort units by their current vitality, sorting ones below the threshold value to the end end of the list. Use this and the other “Tactical AI Filter” actions to set up an AI Filter, which can then be used in a “Tactical AI Filter - Run” function to filter a unit group.

# Arguments

  • aifilter — Filter
  • fixed — Vitality
  • fixed — Threshold

Returns — void

native void AISetFilterLifeSortReference(
	aifilter filter,
	fixed value,
	fixed distance,
);

Category: AI Advanced / Filters / Actions

# Examples

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:245

    AISetFilterAlliance(filter, c_playerGroupEnemy);
    AISetFilterLifePerMarker(filter, damage*0.5, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:441

    AISetFilterBits(filter, UnitFilterStr("-;Missile,Self,Stasis,Dead,Hidden,Invulnerable"));
    AISetFilterLifePerMarker(filter, damage, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:562

    AISetFilterAlliance(filter, c_playerGroupEnemy);
    AISetFilterRange(filter, aiUnit, AIAbilityFixed(player, c_AB_ConsumeDNA, c_fieldRange0));
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);

    candidateGroup = AIGetFilterGroup(filter, scanGroup);

campaigns/liberty.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:669

        damage = AIEffectFixed(player, c_EF_PlasmaBlastDamage, c_fieldAmount);
        AISetFilterLife(filter, damage*c_minDamageFraction, c_noMax);
        AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
        
        //  Get the group with all buildings first in case the hostile building group has none.

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:245

    AISetFilterAlliance(filter, c_playerGroupEnemy);
    AISetFilterLifePerMarker(filter, damage*0.5, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:441

    AISetFilterBits(filter, UnitFilterStr("-;Missile,Self,Stasis,Dead,Hidden,Invulnerable"));
    AISetFilterLifePerMarker(filter, damage, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:562

    AISetFilterAlliance(filter, c_playerGroupEnemy);
    AISetFilterRange(filter, aiUnit, AIAbilityFixed(player, c_AB_ConsumeDNA, c_fieldRange0));
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);

    candidateGroup = AIGetFilterGroup(filter, scanGroup);

campaigns/swarm.sc2campaignbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:669

        damage = AIEffectFixed(player, c_EF_PlasmaBlastDamage, c_fieldAmount);
        AISetFilterLife(filter, damage*c_minDamageFraction, c_noMax);
        AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
        
        //  Get the group with all buildings first in case the hostile building group has none.

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:1567

    AISetFilterBits(filter, UnitFilterStr(AIAbilityStr(player, c_AB_Disintegration, c_fieldTargetFiltersAB)));
    AISetFilterLife(filter, c_aiDisintegrationMinDamage, c_noMax);
    AISetFilterLifeSortReference(filter, c_aiDisintegrationDamage, c_aiDisintegrationDamage*c_distanceFromDamage); 

    enemyGroup = AIGetFilterGroup(filter, scanGroup);

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:53

    AISetFilterMarker(filter, c_noMarkersMin, c_noMarkersMax, mark);
    AISetFilterLife(filter, c_minCannonDamage, c_noMax);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
    //  Filter out units that can't attack allies since this ability is a disable.
    //

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:218

    AISetFilterRange(filterAI, aiUnit, AIAbilityFixed(player, c_AB_Snipe, c_fieldRange0) + 1);
    AISetFilterLifePerMarker(filterAI, damage, mark);
    AISetFilterLifeSortReference(filterAI, damage, damage*c_distanceFromDamage);

    //  Select starting from the end, to obtain the target that has health closest to snipe

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:278

    AISetFilterRange(filterAI, aiUnit, AIAbilityFixed(player, c_AB_SteadyTargeting, c_fieldRange0) + 1);
    AISetFilterLifePerMarker(filterAI, damage, mark);
    AISetFilterLifeSortReference(filterAI, damage, damage*c_distanceFromDamage);

    //  Select starting from the end, to obtain the target that has health closest to snipe

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:462

    AISetFilterBits(filter, UnitFilterStr("-;Missile,Self,Stasis,Dead,Hidden,Invulnerable"));
    AISetFilterLifePerMarker(filter, damage, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1237

    AISetFilterLife(filter, damage*c_minDamageFraction, c_noMax);
    AISetFilterMarker(filter, c_noMarkersMin, c_noMarkersMax, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
    
    //  Select starting from the end, which is the target who's health is closest to the missile's

mods/core.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1652

        AISetFilterLife(filter, c_minLockOnDamage, c_noMax);
    }
    AISetFilterLifeSortReference(filter, c_minLockOnDamage, c_minLockOnDamage*c_distanceFromDamage);

    targetGroup = AIGetFilterGroup(filter, scanGroup);

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

    // Automatic Variable Declarations
    // Implementation
    AISetFilterLifeSortReference(lp_filter, lp_damage, lp_distance);
}

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:2041

        AISetFilterBits(lv_canidatesFilter, UnitFilter((1 << c_targetFilterVisible), 0, (1 << c_targetFilterStructure) | (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32)) | (1 << (c_targetFilterHallucination - 32)) | (1 << (c_targetFilterInvulnerable - 32)) | (1 << (c_targetFilterSummoned - 32))));
        AISetFilterRange(lv_canidatesFilter, lp_aIUnit, lv_abilityRange);
        AISetFilterLifeSortReference(lv_canidatesFilter, 100.0, 50);
        lv_canidates = AIGetFilterGroup(lv_canidatesFilter, lp_nearByUnits);
        libNtve_gf_AICast(lp_aIUnit, OrderTargetingUnit(AbilityCommand("MutatorAmonDehakaDrag", 0), UnitGroupUnit(lv_canidates, UnitGroupCount(lv_canidates, c_unitCountAlive))));

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:2137

        AISetFilterBits(lv_targetFilter2, UnitFilter((1 << c_targetFilterVisible), 0, (1 << c_targetFilterStructure) | (1 << c_targetFilterMissile) | (1 << c_targetFilterBuried), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32)) | (1 << (c_targetFilterHallucination - 32)) | (1 << (c_targetFilterInvulnerable - 32))));
        AISetFilterRange(lv_targetFilter2, lp_aIUnit, lv_abilityRange);
        AISetFilterLifeSortReference(lv_targetFilter2, lv_abilityDamage, (lv_abilityDamage * 0.2));
        lv_canidates = AIGetFilterGroup(lv_targetFilter2, lp_nearByUnits);
        libNtve_gf_AICast(lp_aIUnit, OrderTargetingUnit(AbilityCommand("MutatorAmonNovaWeaponImprovedCanisterRifleSnipe", 0), UnitGroupUnit(lv_canidates, UnitGroupCount(lv_canidates, c_unitCountAlive))));

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:2188

        AISetFilterBits(lv_targetFilter2, UnitFilter((1 << c_targetFilterVisible), 0, (1 << c_targetFilterStructure) | (1 << c_targetFilterMissile) | (1 << c_targetFilterBuried), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32)) | (1 << (c_targetFilterHallucination - 32)) | (1 << (c_targetFilterInvulnerable - 32))));
        AISetFilterRange(lv_targetFilter2, lp_aIUnit, 10.0);
        AISetFilterLifeSortReference(lv_targetFilter2, 160.0, 40);
        lv_canidates = AIGetFilterGroup(lv_targetFilter2, lp_nearByUnits);
        AISetFilterBits(lv_targetFilter2, UnitFilter((1 << c_targetFilterVisible), 0, (1 << c_targetFilterMissile) | (1 << c_targetFilterBuried), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32)) | (1 << (c_targetFilterHallucination - 32)) | (1 << (c_targetFilterInvulnerable - 32))));

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:2330

    lv_blinkDistance = StringToFixed(CatalogFieldValueGet(c_gameCatalogEffect, "MutatorAmonZeratulBlink", "Range", lp_owner));
    AISetFilterPlane(lv_canidatesFilter, c_planeGround);
    AISetFilterLifeSortReference(lv_canidatesFilter, lv_slashDamage, (lv_slashDamage * 0.2));
    if ((UnitAbilityGetCooldown(lp_aIUnit, "MutatorAmonZeratulBlink", "Abil/MutatorAmonZeratulBlink") <= 0.0)) {
        AISetFilterRange(lv_canidatesFilter, lp_aIUnit, lv_blinkDistance);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:601

    AISetFilterAlliance(filter, c_playerGroupEnemy);
    AISetFilterLifePerMarker(filter, damage*0.5, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:797

    AISetFilterBits(filter, UnitFilterStr("-;Missile,Self,Stasis,Dead,Hidden,Invulnerable"));
    AISetFilterLifePerMarker(filter, damage, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:918

    AISetFilterAlliance(filter, c_playerGroupEnemy);
    AISetFilterRange(filter, aiUnit, AIAbilityFixed(player, c_AB_ConsumeDNA, c_fieldRange0));
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);

    candidateGroup = AIGetFilterGroup(filter, scanGroup);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:993

    AISetFilterAlliance(filter, c_playerGroupEnemy);
    AISetFilterRange(filter, aiUnit, (AIAbilityFixed(player, c_AB_ConsumeDNA, c_fieldRange0))-1);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);

    candidateGroup = AIGetFilterGroup(filter, scanGroup);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:1110

    damage = AIEffectFixed(player, c_EF_PlasmaBlastDamage, c_fieldAmount);
    AISetFilterLife(filter, damage*c_minDamageFraction, c_noMax);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
    
    airAllies = AINearbyPlaneTest(UnitGetPosition(aiUnit), player, AIAbilityFixed(player, "HybridDominatorVoidPlasmaBlast", c_fieldRange0), c_planeAir, c_unitAllianceAlly);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactCampAI.galaxy:1393

        damage = 75; //the ability doesn't actually do damage, but should target higher life structures anyways
        AISetFilterLife(filter, damage*c_minDamageFraction, c_noMax);
        AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
        
        //  Get the group with all buildings first in case the hostile building group has none.

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactProtAI.galaxy:1561

    AISetFilterBits(filter, UnitFilterStr(AIAbilityStr(player, c_AB_Disintegration, c_fieldTargetFiltersAB)));
    AISetFilterLife(filter, c_aiDisintegrationMinDamage, c_noMax);
    AISetFilterLifeSortReference(filter, c_aiDisintegrationDamage, c_aiDisintegrationDamage*c_distanceFromDamage); 

    enemyGroup = AIGetFilterGroup(filter, scanGroup);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:58

    AISetFilterMarker(filter, c_noMarkersMin, c_noMarkersMax, mark);
    AISetFilterLife(filter, c_minCannonDamage, c_noMax);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
    //  Filter out units that can't attack allies since this ability is a disable.
    //

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:220

    AISetFilterRange(filterAI, aiUnit, AIAbilityFixed(player, c_AB_Snipe, c_fieldRange0) + 1);
    AISetFilterLifePerMarker(filterAI, damage, mark);
    AISetFilterLifeSortReference(filterAI, damage, damage*c_distanceFromDamage);

    targetGroup = AIGetFilterGroup(filterAI, scanGroup);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:270

    AISetFilterRange(filterAI, aiUnit, AIAbilityFixed(player, c_AB_SteadyTargeting, c_fieldRange0) + 1);
    AISetFilterLifePerMarker(filterAI, damage, mark);
    AISetFilterLifeSortReference(filterAI, damage, damage*c_distanceFromDamage);

    //  Select starting from the end, to obtain the target that has health closest to snipe

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:442

    AISetFilterBits(filter, UnitFilterStr("-;Heroic,Missile,Stasis,Item,Dead,Hidden,Invulnerable"));
    AISetFilterLifePerMarker(filter, damage, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage); 
    targetGroup = AIGetFilterGroup(filter, scanGroup);
    if (targetGroup == null) {

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1209

    AISetFilterLife(filter, damage*c_minDamageFraction, c_noMax);
    AISetFilterMarker(filter, c_noMarkersMin, c_noMarkersMax, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
    
    //  Select starting from the end, which is the target who's health is closest to the missile's

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactTerrAI.galaxy:1599

        AISetFilterLife(filter, c_minLockOnDamage, c_noMax);
    }
    AISetFilterLifeSortReference(filter, c_minLockOnDamage, c_minLockOnDamage*c_distanceFromDamage);

    targetGroup = AIGetFilterGroup(filter, scanGroup);

mods/starcoop/starcoop.sc2modbase.sc2data/TriggerLibs/Tactical/TactZergAI.galaxy:425

    AISetFilterAlliance(filter, c_playerGroupAlly);
    AISetFilterLife(filter, c_aiConsumptionTargetMinLife, c_noMax);
    AISetFilterLifeSortReference(filter, c_aiConsumptionTargetMinLife, c_aiConsumptionTargetMinLife*c_distanceFromDamage); 
    
    consumptionTargets = AIFindUnits(player, null, UnitGetPosition(aiUnit), 5.0, c_noMaxCount);

mods/warcoop/warclassicsystem.sc2modbase.sc2data/TriggerLibs/Tactical/TacticalAIWar3.galaxy:196

    //UnKillable Filters Marker;
    AISetFilterLifePerMarker(filter, damage, mark);
    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
    AISetFilterLifePerMarker(filterBonus, damage, mark);
    AISetFilterLifeSortReference(filterBonus, damage, damage*c_distanceFromDamage);

mods/warcoop/warclassicsystem.sc2modbase.sc2data/TriggerLibs/Tactical/TacticalAIWar3.galaxy:198

    AISetFilterLifeSortReference(filter, damage, damage*c_distanceFromDamage);
    AISetFilterLifePerMarker(filterBonus, damage, mark);
    AISetFilterLifeSortReference(filterBonus, damage, damage*c_distanceFromDamage);
    //Killable Hero
    targets= AIGetFilterGroup(filterKillable, heroes);